Results 1 to 10 of 10
Thread: Creating .Jar File?
- 08-11-2011, 06:01 PM #1
Creating .Jar File?
How do I create a Jar file? I tried to follow the tutorial on the tutorial page for Java but I really don't know what to do with the manifest file.
When I compile my file "Engine.java" to a class file I get two files "Engine.class" & "Engine$1.class". I ofcorse run the Engine.class file when I run the program.
When I edit the manifest file I type in "Main-Class: Engine". It works without errors, but the window that I want to pop up does not pop up. Have I done anything wrong with it? By the way, I have a lot of images that is in a folder called "Img" which I also have into the Jar file. have I done anything wrong? Do I need to add something in the Manifest files to get it working? Please help!
Give me a short tutorial if possible. I've tried "A LOT" of stuff.
- 08-11-2011, 06:25 PM #2It works without errors
Have you put everything the program needs in a jar file?
Did you copy the jar file to a test folder that contained only the jar file?
How are you executing the jar file?
Open a command prompt, change to the test folder with the jar file and enter:
java -jar <YOURJAR>.jar
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
- 08-11-2011, 09:03 PM #3
The error that I get when I run it in the way you just telled me about is:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
"ImageIcon error, what?" I have all of my image files into a folder called "img" into the .JAR file which I also have out of the .JAR file where I run it normal with "Java Engine". Anything that I have to do with the manifest file? Else just tell me what I should do.
- 08-11-2011, 09:08 PM #4at javax.swing.ImageIcon.<init>(Unknown Source)
To read an image that is in a jarfile from code that is inside of the jar file, you need to read from a resource and not from a file. Change how you get the image bytes to use the getResource or getResourceAsStreams which will look for the image file on the classpath which will be in the jar file that the code is in.
Do a Search here of the Forum for code samples using those methods
- 08-11-2011, 09:31 PM #5
But, right now I am using "new ImageIcon(getClass().getResource("img\\IMAGE.png") )" is'nt that good? How can I change it so that it starts to work again?
- 08-11-2011, 09:33 PM #6
Try Changing the \\ to /
is in a folder called "Img"
- 08-11-2011, 09:43 PM #7
I changed the "\\" to "/" & everything started to work. But there is one thing that I still don't understand. Why is "\\" working when you are running a .class file & not working when you are running a .Jar while the "/" works for both?
- 08-11-2011, 09:45 PM #8
\\ is for the Window's OS when you want to find a file on a disk,
/ is for java's classpath which can be on disk or in a jar
- 08-11-2011, 10:00 PM #9
Aah, thanks for all of the help! I really appreciate it. I will definitely continue using this forum for Java, it's totally awsome!
- 08-11-2011, 10:00 PM #10
- By renu in forum New To JavaReplies: 2Last Post: 05-26-2011, 05:38 AM
- By aruna.hcu in forum New To JavaReplies: 25Last Post: 01-06-2010, 07:15 PM
- By Wataru in forum New To JavaReplies: 3Last Post: 07-22-2009, 06:02 AM
- By po0oker in forum Advanced JavaReplies: 3Last Post: 04-04-2008, 07:49 PM
- By psn in forum Enterprise JavaBeans (EJB)Replies: 1Last Post: 01-06-2008, 06:01 AM