简体   繁体   中英

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

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

Suggestions needed.

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).

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

除非您在maven项目中的pom.xml (高效)Java源文件中明确指定它,否则请转到src/main/java

Java文件总是在src / main / java中,并建议保持这种方式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM