7

I try to build .war file by using maven plugin:

 <plugin> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <warSourceDirectory>WebContent</warSourceDirectory> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> 

My project structure looks like:

/main/webapp/WEB-INF/ /main/webapp/WEB-INF/spring/... /main/webapp/WEB-INF/web.xml /main/webapp/public/... /main/webapp/resources/... /main/webapp/views/... 

After building, my war file contains only WEB-INF and META-INF. All other content of webapp directory is missing (public, resources and views). Furthermore the WEB-INF dir in .war file consists only /classes and /lib directories (/WEB-INF/spring and WEB-INF/web.xml are missig).

How to tell maven to pack all webapp and WEB-INF directory content into war file?

3 Answers 3

2

There is a mismatch between your configuration of the maven-war-plugin and the structure of your project. With <warSourceDirectory>WebContent</warSourceDirectory>, you are configuration the maven-war-plugin to look for your webapp sources inside the WebContent directory. However, your sources are in main/webapp.

I suggest you move all of your webapp sources inside src/main/webapp (instead of main/webapp) and update the maven-war-plugin configuration to:

<plugin> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> 

By default, the maven-war-plugin will be looking for your webapp sources inside src/main/webapp.

Sign up to request clarification or add additional context in comments.

Comments

0

You can package your project using Maven by using following command in your command-line.

mvn clean package 

Comments

0

Take a look at the Maven layout definition: The webapp folder should be in src/main/webapp instead of main/webapp. Alternatively you can also force maven to look in a different directory for your resources. See https://maven.apache.org/pom.html#Build_Settings

1 Comment

Please note the slight typo in this answer: the webapp folder should be src/main/webapp

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.