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

I have a gwt web project that should use application.properties (client side) loaded as TextResource into the code. Everything works fine, but now I want to centralize all property values ​​in maven pom.xml. So I made application.properties with placeholders such as key1 = $ {param1}, and in the parameterized parameter pom.xml I param1Value

So what happens is that maven replaces the placeholders in application.properties in the destination directory, but it seems like the gwt compiler uses the application.properties file from src / main / resources. I checked the compiled js files, and there I see that the placeholder is not replaced by its value from pom.xml (the target .properties application is correct).

UPDATE: The problem is that the properties file that I am filtering is a package of gwt message resources, and from what I saw, maven creates a “generated” folder and places the generated java file based on the properties file found in the source root folder project, and not in the target folder. After that, he includes it in a shared javascript file. This means that I have two options: 1) tell the resource plugin to overwrite the properties file located in the sources folder (I am not opposed to this, because I will have problems with the server in the next subversion update) 2) tell gwt- maven-plugin to search for properties file in target / classes folder, which I think is impossible

What do you think?

+6
source share
2 answers

I solved the same problem using resources: copying resources and the build-helper plugin. In particular, configure the resource 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 enable it using the build assistant:

  <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> 
+4
source

I was able to use maven filtering for property files used in GWT compilation.
I am using the com.google.gwt.i18n.client.Constants interface.

It allows you to initialize an interface that extends constants, with methods that return values ​​taken from the properties file.
This properties file can be processed using maven filtering.

This is very easy to do:

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

One caveat: filtering does not work in gwt dev mode

The result can be checked in the target. The installed folder in which the Java interface will be implemented using the filtered properties.

+1
source

Source: https://habr.com/ru/post/896316/


All Articles