简体   繁体   English

Maven在生成过程中排除文件

[英]Maven Exclude Files During Build

I am having problems getting Maven to build my webapp without including extraneous development file, such as unminified script and css files. 我在使Maven生成我的Web应用程序而没有包括无关的开发文件(如未缩小的脚本和CSS文件)时遇到问题。

First i tried using exclude in combination with webResources 首先我尝试将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>

The result was the contents of WEB-INF being duplicated in the project root and no excluded directories or files. 结果是WEB-INF的内容在项目根目录中重复,并且没有排除的目录或文件。

So, I looked around here and found this: maven2: excluding directory from WAR but running mvn clean package using either warSourceExcludes or packagingExcludes results in the directories i'm trying to exclude not being, well, excluded... 所以,我环顾四周,发现了这一点: maven2:从WAR排除目录,但使用warSourceExcludespackagingExcludes运行mvn clean package结果导致我试图排除的目录不被排除在外,好吧,...

The build section of my pom.xml 我的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>

Building the project with these settings results in the following project structure: 使用这些设置构建项目将导致以下项目结构:

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

This is my first time using a build tool, so i'm probably overlooking something simple but in the meantime, this is driving me crazy. 这是我第一次使用构建工具,因此我可能忽略了一些简单的东西,但与此同时,这使我发疯。 Any suggestions or obvious problems with my xml? 我的xml有任何建议或明显问题吗?

First you should read the documentation of the maven-war-plugin cause the packagingExclude is intended for a different purpose, but in your case you need to do the configuration in that way : 首先,您应该阅读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