Results 1 to 12 of 12
Like Tree1Likes
  • 1 Post By eRaaaa

Thread: Help, cannot make my simple program an executable jar

  1. #1
    leoxy520 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Help, cannot make my simple program an executable jar

    Hey guys, I am very new to Java and its IDE.

    Java Code:
    import javax.swing.*;
    
    public class program {
       public static void main(String[] args) {
          JOptionPane.showMessageDialog(null,"Hey, you guys!");
          System.exit(0);
       }
    }
    So I have this little program, that all it does is prints out a message box saying "Hey, you guys".
    After I have exported it from Eclipse as a Runnable Jar File, and ran it from the desktop, I get the error" Could not find the main class: program, Program will exist".
    I can run it fine in the IDE, but I can't outside of the IDE.
    I really want to distribute my programs, but this problem is bugging me. I have googled for hours; i tried the launch4j program for Windows, and I still could not get it to work.
    So any help would be great, greatly appreciated.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Help, cannot make my simple program an executable jar

    Is there a MANIFEST in the jar file, and does that manifest refer to your program class (which should be Program really) as the entry point?

  3. #3
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Help, cannot make my simple program an executable jar

    How do you ran the jar file? With a double-click? If so, can you run it from the command line with java -jar .... ? Maybe there is a problem with the file association : java - "Could not find the main class" when double-clicking .jar file - Stack Overflow

  4. #4
    leoxy520 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Help, cannot make my simple program an executable jar

    Yes, I just double clicked on the jar file. I can run it in the command line, but that is what I don't do because it is unfriendly to the users.
    I extracted the jar and there is a manifest file in it, and it looks like this
    Java Code:
    Manifest-Version: 1.0
    Class-Path: .
    Main-Class: program
    The Main-Class part looks right, I am not sure about the rest though.

  5. #5
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Help, cannot make my simple program an executable jar

    Quote Originally Posted by leoxy520 View Post
    Yes, I just double clicked on the jar file. I can run it in the command line
    Click the link in my post and read it :)
    Tolls likes this.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is online now Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: Help, cannot make my simple program an executable jar

    And observe coding conventions: class names begin with an uppercase letter.
    Code Conventions for the Java(TM) Programming Language: Contents

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    leoxy520 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Help, cannot make my simple program an executable jar

    Quote Originally Posted by eRaaaa View Post
    Click the link in my post and read it :)
    Would the method vary if the program was a console program?

  8. #8
    leoxy520 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Help, cannot make my simple program an executable jar

    Update, I have done all the file association steps.
    Now when I double click the jar file, nothing appears, not even a console flash.
    I am using the Launch4j program, and it gives me an .exe. It works now, but running .jar is still impossible

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

    Default Re: Help, cannot make my simple program an executable jar

    To get any error messages from the java program, open a command prompt, change to the folder with the jar file and enter the command: java -jar <THEJARFILENAME>.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.

  10. #10
    leoxy520 is offline Member
    Join Date
    Jan 2012
    Posts
    5
    Rep Power
    0

    Default Re: Help, cannot make my simple program an executable jar

    Thanks for all the help so far.
    I have gotten the jar to work, if they are gui programs.
    When they are just console programs, nothing appears when I double click them, and they will work in CMD of course.
    If I wrap them with launh4j, it works fine. I think it is just a program of console jar program ?

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Help, cannot make my simple program an executable jar

    Ah, by default the exectubale jar is launched by javaw, which is for GUI apps.
    You'll probably want to write a bat file for launching your app using java instead.

  12. #12
    switch's Avatar
    switch is offline Member
    Join Date
    Jan 2012
    Location
    U.S.A.
    Posts
    19
    Rep Power
    0

    Default Re: Help, cannot make my simple program an executable jar

    I used your code, compiled it and ran it in the editor. It ran just fine. I opened the program from the program.jar file and it ran just fine. I use the NetBeans 7.0 IDE.

Similar Threads

  1. How do I make a Java file executable
    By jacatone in forum Java Applets
    Replies: 13
    Last Post: 01-30-2014, 06:27 PM
  2. Replies: 4
    Last Post: 07-23-2011, 08:08 PM
  3. Replies: 0
    Last Post: 01-25-2011, 05:37 AM
  4. Replies: 3
    Last Post: 08-10-2009, 06:34 AM
  5. How , Can I make a executable for distrubution.
    By arpitvavadia in forum AWT / Swing
    Replies: 2
    Last Post: 09-08-2008, 06:19 PM

Posting Permissions

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