与我的配置文件相比,如何告诉Maven打包文件

时间:2016-02-02 21:30:35

标签: java maven

我在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

但我现在一直没有提出任何问题,为什么?

enter image description here

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:0)

正如maven war plugin所述,src / main / webapp是Web应用程序源的默认文件夹。因此,src / main / webapp中的所有文件都将自动添加到war中。尝试将addin文件夹移到src / main / webapp之外。 如果您无法移动文件夹,则需要使用'exclude'标记作为exaplained here

答案 1 :(得分:0)

我建议您提前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节点,因为我已经包含在我的scriptlet中......但假设您的web.xml文件不需要过滤。 (他们呢?)