Maven war plugin copy src/main/webapp to classes

Viewed 3634

Dear stackoverflow members, I am facing a strange issue with Maven war plugin.

I have comfigurted my eclipse project directory structure as:

Project
|-- pom.xml
 -- src
     -- main
        |-- java
         -- resources
         -- webapp
            |-- WEB-INF
                -- web.xml  

When I run the maven build command, all the files present within the webapp directory are copied to the classes folder which is strange to me. The resultant directory structure in the generate war file is:

|-- META-INF
 -- WEB-INF
    -- classes
       -- 
       -- META-INF
       -- WEB-INF

I didn't expect the META-INF and WEB-INF folders within the classes folder. It's duplicating the data which is not required for the classes folder and these folders are already there at the root of the war file.

Please let me know how to restrict the maven war builder to exclude META-INF and WEB-INF going to classes folder ?

3 Answers

That happened to me also. You'll probably have as a resource the path /src/main/webapp

<project>
...
    <build>
    ...
        <resources>
            ...
            <resource>
                <directory>src/main/webapp</directory>
            </resource>
        </resources>
    </build>
</project>

This is why you have all its content in the resultant WEB-INF/classes/ The solution is to exclude the content:

        <resource>
            <directory>src/main/webapp</directory>
            <excludes>
                <exclude>**/*</exclude>
            </excludes>
        </resource>

Hope this help

This happened to me because I defined webapp folder as a source folder in eclipse. In turn it copies these files to target/classes and packs them under war classes folder.

Related