Forums Register Login

Using absolute path bundle file

+Pie Number of slices to send: Send
Hello ,

Normally when i want to use a bundle file found in my classpath, i use this :

But i prefer to put the "languages" folder outside the jar, so is it possible to use a bundle file which is outside the classpath of my application ?, something like that :

Thanks . . .

1
+Pie Number of slices to send: Send
I think you can use the getBundle method that takes a ClassLoader, and provide a URLClassLoader:
+Pie Number of slices to send: Send
Yes, you're right Rob. This will help me to load other resources.
I tried it and it worked fine.

Thanks Rob
+Pie Number of slices to send: Send
Hi,

the solution from Rob works, while i am in the EclipseIDE. But when i export it to jar and run this via JavaWebStart, it will not work.



In my JAR i have a messageFile named "messages_en.properties" (the default property file) with 3 key/value-pairs
I put into the "c:\temp" a messagefile named "messages_en_var1.properties" with only one key/value-pair, which shall override the existing key/value from the default properties

While i testing it in Eclipse IDE, the new Loader will find the extern message File, gets the one key which should be changed and takes for the other keys the default propteries.
But when i try it via JavaWebStart, it will not work. What happens is, that the application ONLY finds the resource file from the tmp-directory. The default properties will not be sourced.

Has anyone an idea?

Thanks
+Pie Number of slices to send: Send
Are you really using C:\tmp as the name of your file? When you use web start you are probably using absolute paths, so you will not find the file. Is there a copy of that file in your .jar file? What is its PATH and location?
+Pie Number of slices to send: Send
More to the point, when you run the application via Web Start it's going to be run on somebody else's computer. They don't have access to your C: drive. So if you plan to run your application that way, you should put the ResourceBundle in the jar file and access it in the usual way, as a resource.
+Pie Number of slices to send: Send
I am sorry for my explaination, i tried to keep it simple with the given example...

What i have:

A project with the following structure

com.myexample.test



That means, the messages.properties will be the default. When i have a Locale with en (Locale.English), then he will pick the "messages_en.properties" and when there is missing one key, they will be fallback to default "messages.properties" (for only this key/value)
The message*.properties are in the jar-File and will be distributed. So everyone with access can get it

All works very fine .


Now, i want the ability to change/add some Strings without touching the jar-files (i cant touch them after distribution cause of signing the jar-files .....)
Therefore, i tried to put "messages_de.properties" in a web-path ( http://somedomain.com/jws-stuff/com/myexample/test/ )

When i start it with eclipse, he tries to find the messages_de.properties. I give the URLClassloader the "start-folder" (http://somedomain.com/jws-stuff/) and he will find, in dependency to the BundleName, the following package-structure. Therefore i need to create folders like "http://somedomain.com/jws-stuff/com/myexample/test/"

He use the given key/value pairs specified in the "de.properties" and will fallback to the "messages.properties" in the project, when a key will not be founde.
It works very fine !



But when i export it with the new ClassLoader to a jar-file and start it with JNLP , they will only find the messages_de.properties on the server and DONT fall back to "messages.properties" :/



Here is the code from Messages.java

+Pie Number of slices to send: Send
You should put your resources in a separate jar, and then put it on the classpath along with your main jar. You can then simply replace your language jar without touching the main application.
That is a really big piece of pie for such a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 44309 times.
Similar Threads
not able to locate message.properties using ResourceBundle
ResourceBundle use in Web application
resource bundle error
Problem with ResourceBundle and Weblogic
Set my Java application as the default program to open a file extension
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:48:58.