簡體   English   中英

我如何告訴Maven與我的個人資料相比打包文件

[英]How do I tell Maven to package the file compared to my profiles

我的maven項目中有這種結構

src
|
|_java
|_resources
|_webapp
  |
  |_addin
    |
    |_fckconfig.dev.js
    |_fckconfig.js
    |_fckconfig.prod.js

我的pom.xml:

<properties>
        <webXmlfolder>default</webXmlfolder>
        <profileVersion>defaultVersion</profileVersion>
        <majorVersion>2</majorVersion>
        <minorVersion>50.3-0</minorVersion>
    </properties>

    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <profileVersion>DEV</profileVersion>
                <webXmlfolder>dev</webXmlfolder>
            </properties>
        </profile>

        <profile>
            <id>preprod</id>
            <properties>
                <profileVersion>PREPROD</profileVersion>
                <webXmlfolder>preprod</webXmlfolder>
            </properties>
        </profile>

        <profile>
            <id>prod</id>
            <properties>
                <profileVersion>PROD</profileVersion>
                <webXmlfolder>prod</webXmlfolder>
            </properties>
        </profile>
    </profiles>

    <!-- FIN Profiles -->

    <build>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <resources>
            <resource>
                <directory>src/main/resources/</directory>
                <filtering>true</filtering>
                <includes>
                    <include>**/*.${webXmlfolder}.*</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/webapp/addin</directory> 
                <filtering>true</filtering> 
                <includes> 
                    <include>/addin/*.${webXmlfolder}.*</include> 
                </includes> 
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-web.xml</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <overwrite>true</overwrite>
                            <outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>src/main/config/${webXmlfolder}/WEB-INF</directory>
                                    <filtering>true</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

當我執行mvn clean install -P prod我只想擁有:

src
|
|_java
|_resources
|_webapp
  |
  |_addin
    |
    |_fckconfig.prod.js

但是現在什么也沒發生,我總是歸檔,為什么?

在此處輸入圖片說明

在此處輸入圖片說明

在此處輸入圖片說明

正如為maven war plugin所抱怨的那樣,src / main / webapp是Web應用程序源的默認文件夾。 因此,src / main / webapp中的所有文件都會自動添加到war中。 嘗試將addin文件夾移到src / main / webapp之外。 如果您無法移動文件夾,則需要使用“ exclude”標簽,如此處所述

我建議您先使用maven-war-plugin來根據您的配置文件配置WAR文件的內容:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>default-war</id>
                    <phase>package</phase>
                    <goals>
                        <goal>war</goal>
                    </goals>
                    <configuration>
                        <webXml>src/main/config/${webXmlfolder}/WEB-INF/web.xml</webXml>
                        <warSourceIncludes>*.*</warSourceIncludes>
                        <warSourceIncludes>addin/*.${webXmlfolder}.js</warSourceIncludes>
                    </configuration>
                </execution>
            </executions>
        </plugin>

順便說一下,我注意到如果在package階段執行它,則copy-web.xml插件可能存在不兼容性,因為war插件也總是在同一階段執行:

  • 可以將copy-web.xml移到早期階段。
  • 就像我在我的腳本中所包含的那樣,要么<webxml> maven-war-plugin中獲取<webxml>節點,但是假設您的web.xml文件不需要進行過濾。 (是嗎?)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM