簡體   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