Question

Suppose I have a Maven multi-module Java EE 6 app:

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

As you can see, I'm using resource filtering. The pom in foobar-ear defines the build profiles:

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

And each child project's pom defines resource filtering. In 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>

The intention here is to filter foobar-ear/src/main/application/META-INF/glassfish-resources.xml which contains placeholders for JDBC and JavaMail configuration items which are defined in the filter properties files.

When I build using mvn -Pdev clean install, I get this output in 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/

As you can see, the resources copied to the usual output location are filtered, but those in the EAR directory layout and ear file are not.

Was it helpful?

Solution

I added <filtering>true</filtering> to the maven-ear-plugin configuration and now it works.

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

Reference: Filtering the sources

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top