Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT: Get constants in server side

I'm trying to get the constants (ConstantsWithLookup) stored in the client side in my server side, but it can't figure out how to do it. I have my constants interface and my constants properties in the same folder.

I've tried tips of other similar threads with no success.

I tried Hermes, gwt-i18n-server, gwt-dmesg, GTWI18N, using a ResourceBundle, trying to get source file properties.

For the first two, it seems that the main reason is the outdated support for the newest GWT version. As for the ResourceBundle, it cannot find the properties file because at deployment, there isn't a properties file, just a Constants.class.

I'm trying to avoid changing my properties file to another location (like /WEB-INF/constants).

like image 818
Sekz Jedi Avatar asked Oct 03 '12 18:10

Sekz Jedi


1 Answers

I'm using Hermes with GWT 2.5.0.rc1, and it works fine. Usage:

  • put hermes-1.2.0.jar into war/WEB-INF/lib
  • Then on the server side write something like
MyConstantsWithLookup my = Hermes.get(MyConstantsWithLookup.class, "de");
String string = my.getString(key);
  • A properties file MyConstantsWithLookup.properties must exist in the same package as MyConstantsWithLookup.java, even if that properties file is empty (which might be the case if you're using @DefaultStringValue etc.)
  • Also add MyConstantsWithLookup_de.properties etc.
  • Make sure, that these properties files are copied next to your classes when compiling. Javac doesn't do that, so it must be done in an additional build step (Eclipse usually does this automatically, but it won't happen by itself when you build e.g. with Ant)
  • Many build setups will skip the java and properties files from the "client" package when compiling the server side. In that case, put your constants files in the "shared" package (if you have one).
like image 144
Chris Lercher Avatar answered Nov 10 '22 08:11

Chris Lercher