mavenjakarta-eemaven-ear-plugin

Is it possible to filter a generated Maven EAR plugin application.xml with a file filter?


I'm trying to filter an application.xml file generated by the maven-ear-plugin using file filters. My project structure is the standard for Maven.

Here is my POM file:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>test-filter</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>ear</packaging>

    <properties>
        <prop1>xyz</prop1>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.10.1</version>
                <configuration>
                    <version>6</version>
                    <env-entries>
                        <env-entry>
                            <env-entry-name>env1</env-entry-name>
                            <env-entry-type>java.lang.String</env-entry-type>
                            <env-entry-value>${prop1}</env-entry-value>
                        </env-entry>
                    </env-entries>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Up to here everything works fine. The plugin generates an application.xml file containing the env1 entry with the interpolated value xyz.

The problem is when I move the Maven property prop1 to a properties file and configure a filter:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>test-filter</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>ear</packaging>

    <build>
        <filters>
            <filter>src/main/filters/filter.properties</filter>
        </filters>
        <plugins>
            <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.10.1</version>
                <configuration>
                    <version>6</version>
                    <env-entries>
                        <env-entry>
                            <env-entry-name>env1</env-entry-name>
                            <env-entry-type>java.lang.String</env-entry-type>
                            <env-entry-value>${prop1}</env-entry-value>
                        </env-entry>
                    </env-entries>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

For my understanding of the filters feature, it is equivalent as the properties but using a separate file. Nonetheless, the generated application.xml contains the entry env1 without interpolating ${prop1}.

Of course the file src/main/filters/filter.properties exists and contains:

prop1=abc

Is there something I am missing?


Solution

  • My guess is that the order in which the plugins run does not work in your favor.

    The ear plugin creates the application.xml quite early on: http://maven.apache.org/plugins/maven-ear-plugin/generate-application-xml-mojo.html in process during "generate-resources".

    The resources plugin that does the filtering runs in the next phase: http://maven.apache.org/ref/3.3.9/maven-core/default-bindings.html#Plugin_bindings_for_ear_packaging

    So the properties are probably not read at the time the application.xml is generated.

    An option would be to use the properties plugin: http://www.mojohaus.org/properties-maven-plugin/usage.html and bind it to an early phase to have them available for filtering in the ear plugin.