File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
JNLP and Web Start
Loading a resource
Joined: Mar 07, 2008
Jun 21, 2009 11:09:23
In the root of my project I have a "resources" folder which, among other things, has a few .properties files.
These files are moved into the root of the .jar file, which I export from this project.
In my code, i read these properties as follows:
URL url = ClassLoader.getSystemResource(propertyFile);
I'm not using the following, because, if I understand correctly, this searches relative to the MyClass class,
and hence will not find the file in the root of the .jar file.
URL url = MyClass.class.getResource(propertyFile);
Anyways, both of the above URLs were null when started with Java Web Start. I decided to print the classpath,
String classPath = System.getProperty("java.class.path"); log.info("Classpath is set to: " + classPath);
The result was
0 [javawsApplicationMain] INFO mypackage.MyClass - Classpath is set to: C:\Java\Sun\jdk1.6.0_13\jre\lib\deploy.jar
I was suprised not to see my myJar.jar file in here. Is that the reason it fails? And how can I make sure myJar.jar file is in the classpath?
This is in my .jnlp file:
<resources> <j2se version="1.2+" /> <jar href="myJar.jar" main="true" /> </resources>
I thought that would be enough to put myJar.jar in the classpath, but apparantly not?
Hope somebody can help me,
SCJP 6 (91%), SCJD (91%)
Joined: Mar 07, 2008
Jun 21, 2009 11:21:27
The following does seem to work...
URL url = Thread.currentThread().getContextClassLoader().getResource(propertyFile);
I wonder though, why the following, which I also tried, did not work then?
URL url = MyClass.class.getClassLoader().getResource(propertyFile);
I agree. Here's the link:
subject: Loading a resource
injecting a value into a variable from a build process
ant fileproperties optional task problem
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014