Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Add property file to classpath during runtime

807606Mar 28 2007 — edited Mar 30 2007
Hey,

i have following problem: I wrote a plugin-framework and a testplugin. The testplugin is a jar file and also contains some Properties - files for i18n.
Loading the classes during runtime works properly but my i18n Message class cannot find the resourceBundle, i always get an MissingResource Exception.

But when i add the testplugin Jarfile to the classpath of my startscript it works!

So my idea was to add the properties files to the classpath at runtime, is this possible? Or what else can i do? I tried this code to add them to the classpath:
File jarFile = new File(pathToJar);

URL urlOfJarFile = null;

try {
	urlOfJarFile = jarFile.toURL();
} catch (MalformedURLException e) {}

URLClassLoader urlcl = new URLClassLoader(new URL[] { urlOfJarFile });

			
try {
        clazz = Class.forName(strPackage, true, urlcl);			            
                                    	 	
        urlcl.getResource("com/myProject/messages_de.properties"));	
                                                                                     
        urlcl.getResource("com/myProject/messages.properties"));

} catch (ClassNotFoundException e) {}
Thanks alot....

Thomas

Message was edited by:
OhNo
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 26 2007
Added on Mar 28 2007
8 comments
4,569 views