Jar Resource Access
Hello, all
I'm trying to retrieve an image from within my jar. I have looked at several posts of people who have accomplished this. I think the issue I may be having is specific to the class that uses the image, which belongs to (in this test case) the packagetest package.
This is the main class in the jar:
public class ResourceLoadTest extends JFrame{
public ResourceLoadTest() {
setSize(100,100);
getContentPane().add( new packagetest.ResourcePanelTest());
setVisible(true);
setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
}
public static void main ( String args[] ){
ResourceLoadTest r = new ResourceLoadTest();
}
}
And this is the class in the packagetest package
public class ResourcePanelTest extends JPanel {
ImageIcon img;
public ResourcePanelTest() {
img = new ImageIcon(
getClass().getResource("images"+java.io.File.separ ator+"mixerIcon.gif")
);
}
public void paint( Graphics g ){
g.drawImage( img.getImage(), 10, 10, img.getImageObserver());
}
}
mixerIcon.gif is located in the "packagetest/images" directory, and my app works fine when running normally (not in the jar), but I get a nullpointerexception on the getClass().getResource(...) line when running from within the jar.
I also should point out that when packaging the jar, I'm using the following command
jar cvf ResourceLoadTest .
Thanks for your help :-D
thanks
__________________
thanks
|