This is a very strange problem but this is the fact that when you create a maven web application using “-DarchetypeArtifactId=maven-archetype-webapp” then Java source folders are not created. Rather a ‘/resources‘ folder is created. Files placed in ‘/resources‘ folder are placed in your classpath when a jar or 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.
Step 1: To create a Maven web application, run the below command in your working directory.
mvn archetype:generate -DgroupId=com.howtodoinjava.demo /
-DartifactId=springmvcexample /
-DarchetypeArtifactId=maven-archetype-webapp /
-DinteractiveMode=false
The above command will maven-specific folder structure for a web application inside a working directory. Now add eclipse support (or support for your favorite IDE) into this web application with the below command.
//Change current working directory to application folder
cd springmvcexample
//add eclipse support
mvn eclipse:eclipse
Step 2: Next, Import the web application into eclipse as an existing maven project



Step 3: Create source folders manually [Yeh !! Need to do it manually]

Step 4: Update project build configuration with the command Maven > “Update Project”


That’s all. Your source folders are ready.
Happy Learning !!
Comments