繁体   English   中英

Maven在生成过程中排除文件

[英]Maven Exclude Files During Build

我在使Maven生成我的Web应用程序而没有包括无关的开发文件(如未缩小的脚本和CSS文件)时遇到问题。

首先我尝试将excludewebResources结合使用

<build>     
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warName>ReportRocket-1</warName>
                <webResources>
                    <resource>
                        <directory>src/main/webapp/resources/</directory>
                        <excludes>
                            <exclude>annotated-js/*.js</exclude>
                            <exclude>compiled-js/*.js</exclude>
                            <exclude>css/*.css</exclude>
                            <exclude>less/*.less/exclude>
                        </excludes>
                        <directory>src/main/webapp/WEB-INF</directory>
                        <excludes>
                            <exclude>connection.json</exclude>
                            <exclude>reportRocket.jsp</exclude>
                        </excludes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
    </plugins>
</build>

结果是WEB-INF的内容在项目根目录中重复,并且没有排除的目录或文件。

所以,我环顾四周,发现了这一点: maven2:从WAR排除目录,但使用warSourceExcludespackagingExcludes运行mvn clean package结果导致我试图排除的目录不被排除在外,好吧,...

我的pom.xml的build部分

<build>     
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warName>ReportRocket-1</warName>
                <packagingExcludes>
                    src/main/webapp/resources/annotated-js/,
                    src/main/webapp/resources/compiled-js/,
                    src/main/webapp/resources/css/,
                    src/main/webapp/resources/less/,
                    src/main/webapp/WEB-INF/connection.json
                </packagingExcludes>
            </configuration>
        </plugin>
    </plugins>
</build>

使用这些设置构建项目将导致以下项目结构:

META-INF
resources
    //desired folders
    annotated-js
    compiled-js
    css
    less
WEB-INF
    // desired files
    connection.json

这是我第一次使用构建工具,因此我可能忽略了一些简单的东西,但与此同时,这使我发疯。 我的xml有任何建议或明显问题吗?

首先,您应该阅读maven-war-plugin的文档,因为PackagingExclude是用于其他目的的,但是在您的情况下,您需要以这种方式进行配置

<configuration>
  <webResources>
    <resource>
      <!-- this is relative to the pom.xml directory -->
      <directory>src/main/webapp/resources/</directory>
      <!-- there's no default value for this -->
      <excludes>
        <exclude>annotated-js/**</exclude>
      </excludes>
    </resource>
  </webResources>
</configuration>

暂无
暂无

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

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