Search code examples
javamavenbuildresourceswebapp2

Maven not including resources folder in webapp archetype


I have a simple Maven application that I build with Maven (simply clean install).

The app was generated starting from the maven webapp archetype.

When building and generating the war I want src/main/resources and all of its contents to be included in the .war, however this doesn't happen.

I use the following build in my pom.xml

<build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.glassfish.maven.plugin</groupId>
                <artifactId>maven-glassfish-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

Solution

  • I used the maven-archetype-webapp, the pom is :

    <?xml version="1.0"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <groupId>com.greg</groupId>
        <artifactId>ear-example</artifactId>
        <version>1.0-SNAPSHOT</version>
      </parent>
      <groupId>com.greg</groupId>
      <artifactId>example-war</artifactId>
      <version>1.0-SNAPSHOT</version>
      <packaging>war</packaging>
      <name>example-war Maven Webapp</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
      <build>
        <finalName>example-war</finalName>
      </build>
    </project>
    

    I added a an image and properties file

    $ find src/
    src/
    src/main
    src/main/resources
    src/main/resources/test.img
    src/main/resources/test.properties
    src/main/webapp
    src/main/webapp/index.jsp
    src/main/webapp/WEB-INF
    src/main/webapp/WEB-INF/web.xml
    
    jar tvf target/example-war.war
         0 Thu Jan 19 15:28:18 GMT 2017 META-INF/
       134 Thu Jan 19 15:28:16 GMT 2017 META-INF/MANIFEST.MF
         0 Thu Jan 19 15:28:18 GMT 2017 WEB-INF/
         0 Thu Jan 19 15:28:18 GMT 2017 WEB-INF/classes/
        57 Thu Jan 19 15:24:40 GMT 2017 index.jsp
         0 Thu Jan 19 15:28:16 GMT 2017 WEB-INF/classes/test.img
         0 Thu Jan 19 15:28:16 GMT 2017 WEB-INF/classes/test.properties
       222 Thu Jan 19 15:24:40 GMT 2017 WEB-INF/web.xml
         0 Thu Jan 19 15:28:18 GMT 2017 META-INF/maven/
         0 Thu Jan 19 15:28:18 GMT 2017 META-INF/maven/com.greg/
         0 Thu Jan 19 15:28:18 GMT 2017 META-INF/maven/com.greg/example-war/
       875 Thu Jan 19 15:26:00 GMT 2017 META-INF/maven/com.greg/example-war/pom.xml
       116 Thu Jan 19 15:28:18 GMT 2017 META-INF/maven/com.greg/example-war/pom.properties