I have gwt web project, which must use application.properties (on client side) loaded as TextResource in the code. Everything works fine, but now i want to centralize all properties values in maven pom.xml. So i made application.properties with placeholders like key1=${param1} and in the pom.xml i configured property param1Value
So, what happening is that maven replaces the placeholders in application.properties in target dir, but it seems that gwt compiler uses the application.properties file from src/main/resources. I checked the compiled js files and i there i can see that the placeholder is not replaced with its value from the pom.xml (target's application.properties is correct).
UPDATE: The problem is that, the properties file I am filtering is a gwt messages resources bundle file and from what I saw, maven creates a "generated" folder and puts a generated java file based on the properties file found in the root project sources folder and not in the target folder. After that, it incorporates it in the javascript general file. This means I have two possibilities: 1) tell the resources plugin to overwrite the properties file located in the sources folder (I am not cool with that because I will certanly have problems on the next subversion update) 2) tell gwt-maven-plugin to seek the properties file in the target/classes folder which I think it is impossible
What do you think ?
I resolved the same problem by using resources:copy-resources execution and build-helper plugin. In particular, configure the resources plugin:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>filter-sources</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>${project.build.directory}/gwt-extra</outputDirectory>
<resources>
<resource>
<filtering>true</filtering>
<directory>src/main/filtered-sources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
and include it using build helper:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source-gwt</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/gwt-extra</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
I managed to use maven filtering on properties files used in GWT compilation.
I use the com.google.gwt.i18n.client.Constants interface.
It allows to instanciate an interface that extends Constants, with methods returning values taken from a properties file.
That properties file can be process by maven filtering.
It's really easy to do :
One caveat : filtering is not working in gwt dev mode
Result can be check in the target.generated folder whiwh will contained the java implementation of the interface with the filtered properties used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With