简体   繁体   English

从 Maven 构建中排除 webapp 文件夹

[英]Exclude webapp folder from Maven Build

I was trying to achieve a custom directory structure for my war with maven build.我试图用 Maven 构建为我的战争实现自定义目录结构。 Below is my build command used in pom.xml.下面是我在 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.解压war后,请在下面找到war文件的当前目录结构。 Maven is including complete webapp directory under WEB-INF/Classes , But i want only java class files(ndaws directory). Maven 在 WEB-INF/Classes 下包含完整的 webapp 目录,但我只想要 java 类文件(ndaws 目录)。 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.得到了解决方案,我在 pom 中的更改没有反映,正在从目标下的构建文件夹创建战争。

Thanks谢谢

remove resource directory from maven-resources-pluginmaven-resources-plugin 中删除资源目录
and add warSourceDirectory to maven-war-plugin并将 warSourceDirectory 添加到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.或者,如果使用标记为“资源”的 intelij 和 webapp 文件夹,请选择该文件夹。
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.最后我找到了一个解决我的问题......这是一个类似的情况,但我需要排除 webapp 中的一个文件夹。 I opened my war file using 7zip... The folder that I want to exclude were in the main page.我使用 7zip 打开了我的 war 文件...我想排除的文件夹在主页面上。 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.只需使用要排除的文件夹更改“myfolder”即可。 If that is more than one folder, multiply this line.如果那是多个文件夹,则乘以这一行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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