Author |
Message
|
mustang |
Posted: Thu Mar 30, 2006 1:29 pm Post subject: JavaCompute and Resource Bundle |
|
|
Acolyte
Joined: 07 Feb 2006 Posts: 72
|
WMB 6.
I have a java compute node that uses a number of classes in the same package (same java project, same jar file, same bar file). One of the classes tries to instantiate a ResourceBundle. The properties file target of the getBundle method is also in the same package.
When I instantiate these classes from the command line (using a class with a main method), the ResourceBundle can be loaded without any problems. However, when the java compute node instantiates these classes in a message flow, I get the following error:
java.util.MissingResourceException: Can't find bundle for base name company.com.SecurityConfig, locale en
I have tried these variations:
ResourceBundle rc = ResourceBundle.getBundle("company.com.SecurityConfig", Locale.ENGLISH, this.getClass().getClassLoader());
ResourceBundle.getBundle("company.com.SecurityConfig", Locale.getDefault());
ResourceBundle.getBundle("company.com.SecurityConfig");
The properties are in company.com.SecurityConfig.properties
Any help would be very much appreciated.
Thank you very much |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Mar 30, 2006 1:44 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
How are you deploying the code? Are you putting the jar file in the bar file?
Are you sure that the properties file is being included in the jar file? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Mar 30, 2006 1:45 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Did you look at the Java Compute node sample? _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
mustang |
Posted: Thu Mar 30, 2006 2:04 pm Post subject: |
|
|
Acolyte
Joined: 07 Feb 2006 Posts: 72
|
Quote: |
How are you deploying the code? |
Through the WMB Toolkit
Quote: |
Are you putting the jar file in the bar file? |
Yes
Quote: |
Are you sure that the properties file is being included in the jar file? |
Yes
Quote: |
Did you look at the Java Compute node sample? |
I did. I don't recall seeing sample code for loading ResourceBundles. I will look again. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Mar 30, 2006 2:27 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Are you sure there is no spelling error on the bundle name?
Should it not be com.company.whatever instead of company.com.whatever...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mustang |
Posted: Fri Mar 31, 2006 5:59 am Post subject: |
|
|
Acolyte
Joined: 07 Feb 2006 Posts: 72
|
Quote: |
Are you sure there is no spelling error on the bundle name? |
Yes, and I had other people look just to be extra cautious. In addition, the class has no problem loading the ResourceBundle when it is instantiated from outside the broker (using a class with a main method).
Quote: |
Should it not be com.company.whatever instead of company.com.whatever... |
Yes. I changed the package name when I posted this topic. In my haste I wrote company.com instead of com.company. Our standard is actually co.county.Class and co.county.Resource. So, I should have posted co.county.SecurityConfig for the resource and co.county.SecurityConfig.properties for the properties file. |
|
Back to top |
|
 |
mustang |
Posted: Fri Mar 31, 2006 1:58 pm Post subject: |
|
|
Acolyte
Joined: 07 Feb 2006 Posts: 72
|
Quote: |
Did you look at the Java Compute node sample? |
Yes. I noticed that despite the fact that it appears they put it in the package, they did not fully qualify the resource:
private final static String ROUTING_TABLE_FILE = "routingtable.cfg";
and they used Class.getResourceAsStream
InputStream is = RoutingFileNode.class.getResourceAsStream(ROUTING_TABLE_FILE);
routingTable = new Properties();
routingTable.load(is);
I tried doing it the way the sample did it, and it did not work. This is most confusing! |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Mar 31, 2006 3:15 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Ok back to the drawing board.
To avoid naming problems I usually use getClass().getName().
So the properties need to have the same name as the class.
This does not absolve you, however, from having the jar in which this property file is to be found on the classpath.
On the broker this is deployed, to make sure, you dump the classpath at runtime to know what it is. Then make sure it contains the jar name as
<relative or absolute path>/myjar.jar. In the app you should then be able to access the properties file. The jar may have to be explicitly on the classpath I don't believe that the directory where the jar is will be sufficient.
If nothing else works try extracting from the jar and see if it gets picked up then...
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
kt76 |
Posted: Thu May 04, 2006 1:29 am Post subject: Reading property file from Java compute node |
|
|
Acolyte
Joined: 18 Jan 2004 Posts: 52
|
Im facing a similar issue of reading a property file.
Ive tried everything on this site.
My code is as foll-
InputStream is =JavaCompute.class.getResourceAsStream("myservice.cfg");
Properties properties = new Properties();
properties.load(is);
properties.getProperty("valuel");
The cfg file is available in the jar but still is not able to get the value.
Please help!!! |
|
Back to top |
|
 |
|