Maven – Create java source folders

This is very strange problem but this is fact that when you create a maven web application using “-DarchetypeArtifactId=maven-archetype-webapp” then no java source folder is created. Rather a resources folder is created. Files placed in resources folder are placed in your classpath when war file is created for your web application.

To create java source folders, you MUST create them manually. And then add these folders to your build configuration later.

1) Create maven web application

To Create maven web application , run below command in your working directory.

//No line breaks in below command

mvn archetype:generate -DgroupId=com.howtodoinjava.demo -DartifactId=springmvcexample -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

2) Above command will maven specific folder structure for a web application inside working directory. Now add eclipse support (or support for your favorite IDE) into this web application with below command.

//Change current working directory to application folder
cd springmvcexample

//add eclipse support
mvn eclipse:eclipse

3) Import the web application into eclipse as existing maven project

import-existing-maven-project

import-existing-maven-project-step-2

default-maven-directory-structure

4) Create source folders manually [Yeh !! Need to do it manually]

add-new-folders-in-maven-web-project

5) Update project build configuration with command Maven > “Update Project”

update-maven-project

updated-source-folders

That’s all. Your source folders are ready.

Happy Learning !!

Was this post helpful?

Join 7000+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

Leave a Comment

HowToDoInJava

A blog about Java and related technologies, the best practices, algorithms, and interview questions.