5
votes

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

3 Answers

2
votes

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.

0
votes

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

mvn clean package
0
votes

Take a look at the Maven layout definition: The webapp folder should be in scr/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