Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should I add Java files in web (WAR) project in Maven?

Tags:

java

maven

Where should I have my Java source folder in the Maven web application architecture which results in a WAR?

Suggestions needed.

like image 239
Praneel PIDIKITI Avatar asked Feb 10 '11 14:02

Praneel PIDIKITI


People also ask

Where is WAR file in maven project?

Now, once we execute the mvn install command, the WAR file will be generated inside the target folder. Using the mvn:war:exploded command, we can generate the exploded WAR as a directory inside the target directory.

Where does Web XML go in maven project?

web. xml file is always inside WEB-INF folder, by default Maven is expecting it in there and its the first location that is being searched for a web.


4 Answers

The basic structure that is standard for Maven project is the following.

src/main/java        Application/Library sources
src/main/resources    Application/Library resource
src/main/filters      Resource filter files
src/main/assembly    Assembly descriptors
src/main/config    Configuration files
src/main/webapp    Web application sources
src/test/java        Test sources
src/test/resources  Test resources
src/test/filters      Test resource filter files
src/site              Site

Following the Maven recommendations and normal behavior makes it easier for other people familiar with Maven to easy recognize and understand the structure.

Source/Read more

like image 34
user373455 Avatar answered Nov 09 '22 13:11

user373455


Maven web applications typically do not include java source code. The maven approach is to create a maven project for the "logic" of your web application (this will build into a jar) and create a second maven project for the webapp portion of your web application (this will build into a war). Then in the webapp portion, you introduce a dependency on the "logic" portion.

The end result is that when you build / test your logic jar (which contains servlets, etc), you will deploy that to your local repository and then build your war (which contains jsp pages, web.xml configs, etc).

like image 91
Edwin Buck Avatar answered Nov 09 '22 15:11

Edwin Buck


Unless you explicitly specify it differently in your pom.xml (productive) Java source files in a Maven project go to src/main/java.

like image 39
Joachim Sauer Avatar answered Nov 09 '22 13:11

Joachim Sauer


Java files always go in src/main/java and its advised to keep it that way.

like image 31
Manoj Avatar answered Nov 09 '22 15:11

Manoj