问题描述
我试图让常量(ConstantsWithLookup)存储在客户端在我的服务器端,但它不知道如何去做。我有我的常量界面和我的常量属性在同一个文件夹中。
我尝试了其他类似线程的提示,但没有成功。
我尝试使用ResourceBundle尝试获取源文件属性,然后尝试使用Hermes,gwt-i18n-server,gwt-dmesg,GTWI18N。
对于前两种,似乎主要原因是对最新GWT版本的过时支持。至于ResourceBundle,它无法找到属性文件,因为在部署时,没有属性文件,只有一个Constants.class。
我试图避免将我的属性文件更改为另一个位置(如/ WEB-INF /常量)。
我使用与GWT 2.5.0.rc1,它工作正常。用法:
- 将hermes-1.2.0.jar加入war / WEB-INF / lib
- 然后在服务器端写一些类似于
MyConstantsWithLookup my = Hermes.get(MyConstantsWithLookup.class,de);
String string = my.getString(key);一个属性文件 MyConstantsWithLookup.properties code> must 存在于与 MyConstantsWithLookup.java 相同的包中,即使该属性文件为空(这可能是这种情况)
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).
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).
这篇关于GWT:在服务器端获取常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!