Maven多模块项目复制耳输出,一个没有资源过滤

时间:2012-06-02 05:28:40

标签: java maven ear maven-ear-plugin

假设我有一个Maven多模块Java EE 6应用程序:

foobar/
    foobar-ear/
        src/
            main/
                application/
                    META-INF/
                        MANIFEST.MF
                        glassfish-application.xml
                        glassfish-resources.xml
                filters/
                    dev.properties
                    prod.properties
                    test.properties
        pom.xml
    foobar-web/
    foobar-ejb/
    pom.xml

如您所见,我正在使用资源过滤。 foob​​ar-ear中的pom定义了构建配置文件:

<profiles>
    <profile>
        <id>dev</id>
        <properties>
            <env>dev</env>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>
    <profile>
        <id>test</id>
        <properties>
            <env>test</env>
        </properties>
    </profile>
    <profile>
        <id>demo</id>
        <properties>
            <env>demo</env>
        </properties>
    </profile>
    <profile>
        <id>prod</id>
        <properties>
            <env>prod</env>
        </properties>
    </profile>
</profiles>

每个子项目的pom都定义了资源过滤。在foobar-ear / pom.xml中:

<build>
    ...

    <filters>
        <filter>src/main/filters/${env}.properties</filter>
    </filters>
    <resources>
        <resource>
            <directory>src/main/application</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/application</directory>
            <filtering>false</filtering>
            <excludes>
                <exclude>**/*.xml</exclude>
            </excludes>
        </resource>
    </resources>

    ...
</build>

这里的目的是过滤foobar-ear / src / main / application / META-INF / glassfish-resources.xml,它包含在过滤器属性文件中定义的JDBC和JavaMail配置项的占位符。

当我使用mvn -Pdev clean install构建时,我在foobar-ear中获得此输出:

foobar-ear/
    target/
        classes/
            META-INF/
                MANIFEST.MF
                glassfish-application.xml
                glassfish-resources.xml    <- This one is filtered
        foobar-ear/
            META-INF/
                MANIFEST.MF
                glassfish-application.xml
                glassfish-resources.xml    <- This one is NOT filtered
            lib/
            foobar-ejb.jar
            foobar-web.war
        application.xml
        foobar-ear.ear                     <- ear file. Contents same as foobar-ear/

如您所见,复制到通常输出位置的资源已被过滤,但EAR目录布局和ear文件中的资源不会被过滤。

1 个答案:

答案 0 :(得分:0)

我已将<filtering>true</filtering>添加到maven-ear-plugin配置中,现在可以正常运行。

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <filtering>true</filtering>
                [...]
            </configuration>
        </plugin>
        [...]
    </plugins>
    [...]
</build>

参考:Filtering the sources