Click to See Complete Forum and Search --> : making a jar file with multiple classes and jars
munchy1988
03-28-2007, 12:16 AM
I want to make a jar file that must also contain 2 jar files. is it possible to do this? and how would i go about doing it?
also, i would like to include some picture files and somehow reference them in the jar file somehow. could someone tell me how i could do this?
its been almost a year since i programmed in java, and it sucks relearning it all.
Embedding picture files as resources isn't hard -- just embed them and then use the classpath within your application.
As for embedding jar files, that's not usually done. Instead extract all the classes from the various jars and create one big one.
munchy1988
03-29-2007, 01:51 PM
Embedding picture files as resources isn't hard -- just embed them and then use the classpath within your application.
As for embedding jar files, that's not usually done. Instead extract all the classes from the various jars and create one big one.
i did realize i had to extract the class files first, but im still having difficulty with the images. in the app, i refer to the filename as "images/gold.gif". the file gold.gif is inside the images folder that i put in the jar file. however, when i run the jar file, the images do not work. i was reading that you somehow have to put it to a URL object, but i'm not sure how to do this, nor how to make it work. anyone else know how to make the images work aka easier ways than a URL object?
Here's a little code snippet from some of my old code that should help:
setIconImage(new ImageIcon(getClass().getResource("/com/blah/icon.gif")).getImage());
munchy1988
03-29-2007, 04:17 PM
Here's a little code snippet from some of my old code that should help:
setIconImage(new ImageIcon(getClass().getResource("/com/blah/icon.gif")).getImage());
did you import anything for this to work?
final Image gold = Toolkit.getDefaultToolkit().createImage("images/gold.gif").getScaledInstance(30,40,1);
this is the code i had before. it works if the folder "images" is there with the pics inside of it. i put this folder in the jar file as well, but if the images folder isnt explicitly in the folder that the jar is in, the pictures wont work.
The getClass().getResource() is the key part of finding the file within the jar.
munchy1988
03-29-2007, 08:41 PM
The getClass().getResource() is the key part of finding the file within the jar.
i used that without using the .getImage() in the code. i tried
final Image gold = Toolkit.getDefaultToolkit().createImage(getClass().getResour ce("/images/gold.gif")).getScaledInstance(30,40,1);
its still not working
any other ideas?
Nothing is standing out. I was going to point out the missing leading "/" a couple posts above, but the last example has it. And I have to assume the "images" directory is at the root of the jar file, right?
Can you debug the pieces and find out where it's failing? Something is probably coming back NULL that shouldn't be. Also - how is it not working? Just blank image or a NullPointerException?
edit: I did find this: http://forum.java.sun.com/thread.jspa?threadID=749816&messageID=4287812
where there's a similar problem. The user seems to have issues, but there's a good debugging suggestion towards the bottom, printing out the URL and comparing it to the jar file.