Results 1 to 10 of 10
  1. #1
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default 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.

    Thanks,
    Alerhau

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    It works without errors
    What is the "it" that is working?
    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 Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  3. #3
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    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)
    at Engine.<init>(Engine.java:32)
    at Engine.main(Engine.java:59)

    "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.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    at javax.swing.ImageIcon.<init>(Unknown Source)
    at Engine.<init>(Engine.java:32)
    At line 32 the code is creating an new ImageIcon with a null value.

    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

  5. #5
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    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?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    Try Changing the \\ to /
    is in a folder called "Img"
    vs
    ("img\\IMAGE.png")
    Check the spelling

  7. #7
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    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?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    \\ 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

  9. #9
    Alerhau's Avatar
    Alerhau is offline Senior Member
    Join Date
    Jun 2011
    Location
    Sweden
    Posts
    158
    Rep Power
    4

    Default

    Aah, thanks for all of the help! I really appreciate it. I will definitely continue using this forum for Java, it's totally awsome!

  10. #10
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

Similar Threads

  1. Replies: 2
    Last Post: 05-26-2011, 05:38 AM
  2. creating a file
    By aruna.hcu in forum New To Java
    Replies: 25
    Last Post: 01-06-2010, 06:15 PM
  3. Creating a .jar file
    By Wataru in forum New To Java
    Replies: 3
    Last Post: 07-22-2009, 06:02 AM
  4. creating jar file
    By po0oker in forum Advanced Java
    Replies: 3
    Last Post: 04-04-2008, 07:49 PM
  5. creating .ear file
    By psn in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 01-06-2008, 05:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •