Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: How do I create and run a jar file?

  1. #1
    Junior Member
    Join Date
    Jul 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How do I create and run a jar file?

    Hello!

    I'm just starting out with programming and Java is my first language in which I code. However, while the coding itself is advanced but relatively easy to find information about I have had lots of problems when trying to find information about what to do when my code is ready.

    So, this is my situation:
    I am writing Java in Eclipse and av recently finished a small and simple test program containing a few classes. To show my progress to friends of mine I want to turn this source code into a program and send it to them. The question is, how do I do this?

    I've been able to export the jar file itself from Eclipse but not been able to run it. I've also found tutorials saying that I should modify MANIFEST.MF file but I have not been able to do that, at least not in the right way, as it has not worked yet.


  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    In eclipse, you just export the project as a runnable jar, and include the dependencies... I never had an issue when I did that.

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How do I create and run a jar file?

    Ah, so it's supposed to be simple. It would seem I managed to get it to work now when exporting it as a runnable jar. It was then just run it with the proper command. Sadly I must have missed doing that before, even though I tried for, well, a long time. Last time I mostly exported it as a "regular" jar and tried doing stuff with that, might have messed things up.

    So, thanks anyway, even if you didn't actually answer ^^

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,360
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: How do I create and run a jar file?

    You need to be more specific. What exactly do you mean when you say it doesn't work? Do you get an error? Some strange behavior? Something else?

    Recommended reading: Lesson: Packaging Programs in JAR Files (The Java Tutorials > Deployment)
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Member
    Join Date
    Jul 2012
    Posts
    69
    My Mood
    Relaxed
    Thanks
    1
    Thanked 6 Times in 6 Posts

    Default Re: How do I create and run a jar file?

    I always use "launch4j" to make an exe file. Look up a tutorial on youtube how to use it.

  6. #6
    Junior Member
    Join Date
    Jul 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How do I create and run a jar file?

    Thanks KevinWorkman and Elamre too! I did get it to work though and it runs just fine on my and most of my friends computers.

    However, when one of my friends tries to start the file from the .bat file the rest of us are using, the command prompt which the program runs in (as I said, simple) opens but instantly closes. The same happens when he tries to use other, commercial, java programs that are run in the same way. Therefore I suspect that something might be wrong with his java install. To be noted is that running such jar files has worked for him before. Other specifications of the problem would be that he can run other Java programs that does not involve a command prompt, i.e. Java is installed.

    So, as I haven't yet found anything on Google, I will just go ahead and see if anyone reading this thread could possibly point me in the right direction for this problem too. Is a re-install of Java to be recommended or is there something else to do?

    The command used to run the program is of the type "java -jar FileName.jar" and seems to work for everyone else.

  7. #7
    Member
    Join Date
    Jul 2012
    Posts
    69
    My Mood
    Relaxed
    Thanks
    1
    Thanked 6 Times in 6 Posts

    Default Re: How do I create and run a jar file?

    I've had that problem a lot as well. For some of my friends it was an outdated java version. For the others the .exe worked. Give it a try, it's so much easier.

  8. #8
    Junior Member
    Join Date
    Jul 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How do I create and run a jar file?

    Ah, ok. Thanks! I might try that!

  9. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,360
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: How do I create and run a jar file?

    Get him to run the jar via the command prompt himself. Does he get an exception? It could indeed be that his Java is older than the Java you used to compile the jar. Have him run it in the command prompt himself. If you get something like "unsupported major/minor version", than that means he needs to update his Java (or you need to compile your code so it complies with older Java versions).
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  10. The Following User Says Thank You to KevinWorkman For This Useful Post:

    Ecen (August 2nd, 2012)

  11. #10
    Junior Member
    Join Date
    Jul 2012
    Posts
    16
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How do I create and run a jar file?

    Ok, thanks! I will sure try that!

    Everyone here is so helpful, this has been my first thread, but I will sure stay

  12. #11
    Junior Member
    Join Date
    Jul 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How do I create and run a jar file?

    hello Ecen,
    I am not a Java expert but i can do some research on internet and answer your questions. I have done some research for your problem and found this: How do make jar runnable file? | Techyv.com

    another one is this link:Creating an Executable jar File
    those two may help you to understand the solution.

Similar Threads

  1. We get the exception :Cannot create a file when that file already exists
    By yatin.baraiya in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: May 25th, 2012, 10:33 AM
  2. create excel file
    By deependeroracle in forum Java Theory & Questions
    Replies: 4
    Last Post: February 11th, 2012, 12:26 AM
  3. Replies: 10
    Last Post: January 12th, 2011, 04:48 AM
  4. create a file
    By mos33 in forum Java Theory & Questions
    Replies: 4
    Last Post: December 4th, 2009, 01:21 PM
  5. How to create exe file
    By sirimalla in forum Java Theory & Questions
    Replies: 6
    Last Post: November 1st, 2009, 03:07 AM

Tags for this Thread