Error loading images in Signed Jar, JNLP Application
I am developing JNLP Application 开发者_Python百科and using maven-webstart plugin to create JNLP. When running the application in my local, it works correctly but when I run in Tomcat Server using jnlp, it does not load images and also does not give any exception.
I am loading images as below
new ImageIcon(getClass().getResource("/icons/save.png"))
What is wrong with my code?
Where are your icons located? How do you run a jnlp application inside tomcat? Assuming you don't have a lot of images, you can package them inside one of your packages. Just create a package called com.yourproject.resources and dump some images there. Then the way to access them would be: //define it in some class
public URL obtainImageResource ( String nameOfResource )
{
return getClass().getResource( "/com/yourproject/resources/" + nameOfResource );
}
Do get them with a URL. Then to create the stuff you need:
BufferedImage yourImage = ImageIO.read( yourclaass.obtainImageResource( "yourimagepng.png" ).openStream() );
Note some things: In my setup you need to package your images into your jar.
It's hard to say without more information. You might use jar -tf
to see if the images are in the JAR file. In the meantime, here's a working JWS application that loads images, for reference.
精彩评论