• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using absolute path bundle file  RSS feed

 
Hesham Gneady
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 . . .

 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can use the getBundle method that takes a ClassLoader, and provide a URLClassLoader:
 
Hesham Gneady
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you're right Rob. This will help me to load other resources.
I tried it and it worked fine.

Thanks Rob
 
Steffen Gallus
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Clapham
Sheriff
Posts: 22823
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steffen Gallus
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Stephan van Hulst
Saloon Keeper
Posts: 7973
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!