简体   繁体   中英

Exclude webapp folder from Maven Build

I was trying to achieve a custom directory structure for my war with maven build. Below is my build command used in pom.xml.

<build>
        <finalName>abc</finalName>
                 <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <configuration>
                            <tasks>
                                <mkdir dir="bin" />

                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <!-- here the phase you need -->
                        <phase>validate</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>bin</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/webapp/</directory>
                                </resource>

                            </resources>

                        </configuration>
                    </execution>

                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <warSourceDirectory>bin</warSourceDirectory>
                    <failOnMissingWebXml>false</failOnMissingWebXml>

                </configuration>
            </plugin>

        </plugins>
    </build>

Please find below the current directory structure of war file after unzip the war. Maven is including complete webapp directory under WEB-INF/Classes , But i want only java class files(ndaws directory). I have tried a lot of excluding techniques, But nothing works.
在此处输入图片说明

Got the solution, My changes in pom is not reflecting, war is being created from build folder under target.

Thanks

remove resource directory from maven-resources-plugin
and add warSourceDirectory to maven-war-plugin

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.0.0</version>
    <configuration>
        <warSourceDirectory>src/main/webapp</warSourceDirectory>
    </configuration>
</plugin>

or if using intelij and webapp folder marked 'resoures', select the folder.
open context menu.
Mark Directory as > Unmark as Resources Root

I tryed alot of solutions. In the end I found one that solve my problem... It's a similiar case, but I need to exclude a folder inside the webapp. I opened my war file using 7zip... The folder that I want to exclude were in the main page. I used this:

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

Just change "myfolder" with the folder that you want to exclude. If that is more than one folder, multiply this line.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM