Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT does not use resource properties file from target, but the once in src/main/resources. How to make it with placeholders?

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 ?

like image 446
user358448 Avatar asked Aug 31 '11 11:08

user358448


2 Answers

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>
like image 73
apetrelli Avatar answered Sep 27 '22 20:09

apetrelli


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 :

  • declare an interface extending Constants : XxConstants
  • create a properties file XxConstants.properties in src/main/resource in the same package as your interface
  • activate maven resources filtering so XxConstants.properties is filtered
  • when GWT is compiling (with gwt-maven-plugin), it will generate an instance of XxConstants using the filtered properties file.
  • in your gwt code, create an instance of XxConstants with GWT.create or with gin injection
  • call the methods to get the property values

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.

like image 22
clavelm Avatar answered Sep 27 '22 20:09

clavelm