Bhagwat Chouhan
Bhagwat Chouhan

Reputation: 85

Maven war plugin copy src/main/webapp to classes

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 ?

Upvotes: 5

Views: 4344

Answers (3)

Mert Ülkgün
Mert Ülkgün

Reputation: 154

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.

Upvotes: 0

adoalonso
adoalonso

Reputation: 325

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

Upvotes: 2

varontron
varontron

Reputation: 1157

I had this problem too. It was solved by overriding the maven-war-plugin config by adding it to my pom and including a <packagingExcludes> element:

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1.1</version>
        <configuration>
           <packagingExcludes>**/webapp</packagingExcludes>
           ...
        </configuration>
    </plugin>
</plugin>

This precluded, as in the OP's case, the copying of the contents of ${basedir}/src/main/webapp, including META-INF and WEB-INF, to target/classes/main/webapp and subsequently to target/${finalName}/WEB-INF.

In effect, maven then behaved as desired, putting the contents of ${basedir}/src/main/webapp only into target/${finalName} and subsequently into the ${finalName}.war

Upvotes: 3

Related Questions