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!

ClassLoader in JAR file not loading config file properly

800306May 16 2007 — edited May 17 2007
Hi all,

I have an application that I am going to deploy using JavaWS, and everything works fine except for one little hitch. I have a configuration file, nvacconfig, located at NVAC.jar/config/nvacconfig. I'm trying to load this file into my application using a ClassLoader, but it does not seem to be working.

I have a method from a certain class that loads the configuration file. The class is not important, as it is part of an API that I cannot alter. This class has a load(String file) method, that loads the specified configuration file with a String argument. This works fine when I run my application from the command line and when the configuration file is not located in the JAR, but I need to include this configuration file in my JAR, so I can run my app in the JWS sandbox.

To load the file when it is NOT inside a JAR, and is simply located at config/nvacconfig, I just use:
id.properties.load("config/nvacconfig");
and it loads the configuration file, nvacconfig.

When I include the file in my JAR and try to load it using a ClassLoader, it does not seem to work, and the load method cannot find the file. This is how I am trying to accomplish this:
ClassLoader cl = this.getClass().getClassLoader();
URL url = cl.getResource("config/nvacconfig");
String file = url.toString(); //I have also tried String file = url.getFile();
id.properties.load(file);
This does not work, and I'm not sure why.

Is there something I am doing wrong? Is this the wrong way to go about this?

Any advice would be greatly appreciated.

Thanks,
Dan

Message was edited by:
Djaunl
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 14 2007
Added on May 16 2007
8 comments
1,377 views