Another way to use a resource bundle
Imagine this: You must provide a display widget that extracts the message keys (keys) and message substitution parameters from the database, finds the keys in the Java resource bundle, and then formats the messages and displays them. The only problem is that the resource bundle is in the Web application, not where your widget is located. In fact, Web applications are located on different servers.
This is not a typical use of Java resource bundles, but it could be a nightmare. How do you achieve this? In order not to have a vague explanation, this article includes a sample application for you to download and run. It will make it easier for you to demonstrate and help you do this.
Sample application and resource files
Examples of this case are provided for Ibm®websphere®application Server V7 and Apache Tomcat 6 running Java Platform Standard Edition (Java SE) 6. Java SE 6 is needed because the sample uses Java class Java.util.ResourceBundle.Control to implement a resource bundle load through HTTP, which is not available until Java se 6.
Installing the sample Application
The download sample materials included in this article include:
Sj_tomcat.zip contains:
Remoteresourcebundle.war
Autoparts.war
Autosales.war
Sj_was.zip contains:
Remoteresourcebundleear.ear
Autopartsear.ear
Autosalesear.ear
Sj_source.zip contains Java resources and other files that make up the sample. The resources used in Remoteresourcebundle.war include:
Src/remote/bundle/example/remoteresourcebundleloader.java
Src/remote/bundle/example/productcontextroots.java
Src/remote/bundle/example/messagesbundle.java
Src/remote/bundle/example/messagesbean.java
Src/remote/bundle/example/productcontextroots.properties
webcontent/remotebundledisplay.jsp
The resources used in Autoparts.war include: webcontent/remote/bundle/example/autoparts.properties
The resources used in Autosales.war include: webcontent/remote/bundle/example/autosales.properties