views:

77

answers:

1

I'm writing a Java application that needs to access several resources in a .jar file that is run over JNLP.

While the application works fine in my development environment (Eclipse) it doesn't work when executed through JNLP, apparently because it can't find the resource file in the jar. I've checked the resource file and the resources are most definitely there.

I'm currently using code like:

 someclass.getResourceAsStream("/resources/somefile.png");

What is the correct way to access a resource file in a .jar that will work with JNLP?

+1  A: 

use : this.getClass().getClassLoader().getResourceAsStream(name)
example: myClass.getClass().getClassLoader().getResourceAsStream("resources/somefile.png")

two tips:
1 - use your own class that is in jar file. if used another class - for example Object - fails
2 - name i.e. resource must be without leading '/'

Romain Hippeau
Thanks Romain! This seems to work, I think the problem was using a Java class that wasn't in my jar file
mikera