Results 1 to 7 of 7
  1. #1
    S.Mason is offline Member
    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    Default Can't seem to run a JAR file by cmd line or double-click.

    Well, first I tried to simply double click the file. Nothing happened, for a split second the mouse pointer hourglass showed up and that was it. I stayed up last night doing google seaches and reading articles by other people in different forums to see what I could try. I ended up in the oracle website at one point and tried the deployment tutorial. Everything worked fine with that. Launching it via cmd prompt or double clicking worked fine. I tried making a simple gui with a button and running that and it worked fine as well.
    So then lastly I try to run my program via the cmd prompt and normally I would be fine if an error showed up. I usually don't have a problem figuring those out since I can normally understand or pinpoint the source of the error. But this time the error message is not giving me anything useful. It just spams the entire cmd prompt with this one line
    Java Code:
            at namesmart.NameSMART.<init>(NameSMART.java:28)
    Has this happened to anyone before and if so what is the source of the error? Thank you.

  2. #2
    SnakeDoc is offline Senior Member
    Join Date
    Apr 2012
    Posts
    129
    Rep Power
    0

    Default Re: Can't seem to run a JAR file by cmd line or double-click.

    i've had difficulty before creating runnable JAR files too... in my experience its a HUGE timesaver to just import your project or source files into Eclipse and Export it as a Runnable Jar. I think (might be wrong) that there are two types or Jar files, one that is just a collection of your class files (like a ZIP folder) and the other has a manifest file (and possible supporting classes) that enable your program to run by double clicking the jar. I know when you export from Eclipse as a runnable Jar it includes some other classes from an Eclipse project (org.eclipse i think) that make it runnable.

    Anyways... to start out and if you don't want to use and IDE like Ecplise, have your examined how you are compiling your project into a JAR? Firs test to make sure your program runs at the command line without being in a JAR (just run the class files and make sure no errors) . if it runs there, then you have a problem wiht your JAR creation ... if it doens't run, then you may have a classpath issue or something else causing the problem.

    After you've verified its a working program - then retry making your JAR file. You must inlcude a manifest file that tells the JAR upon execution what class / method to run, otherwise it will give you NoClassDefFound error.

    How to make an executable JAR file

    This link has good explanation of creating the manifest file and pulling eveything into a JAR file (I also think you must have your program as part of a Project and have the correct directory structure, such as com/foo/YourProject/ would be project of com.foo.YourProject).

    Hope that helps get you started... I eventually gave up on making my own JAR and just use Eclipse since it works 100% of the time for me lol!

  3. #3
    S.Mason is offline Member
    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    Default Re: Can't seem to run a JAR file by cmd line or double-click.

    Quote Originally Posted by SnakeDoc View Post
    i've had difficulty before creating runnable JAR files too... in my experience its a HUGE timesaver to just import your project or source files into Eclipse and Export it as a Runnable Jar. I think (might be wrong) that there are two types or Jar files, one that is just a collection of your class files (like a ZIP folder) and the other has a manifest file (and possible supporting classes) that enable your program to run by double clicking the jar. I know when you export from Eclipse as a runnable Jar it includes some other classes from an Eclipse project (org.eclipse i think) that make it runnable.

    Anyways... to start out and if you don't want to use and IDE like Ecplise, have your examined how you are compiling your project into a JAR? Firs test to make sure your program runs at the command line without being in a JAR (just run the class files and make sure no errors) . if it runs there, then you have a problem wiht your JAR creation ... if it doens't run, then you may have a classpath issue or something else causing the problem.

    After you've verified its a working program - then retry making your JAR file. You must inlcude a manifest file that tells the JAR upon execution what class / method to run, otherwise it will give you NoClassDefFound error.

    How to make an executable JAR file

    This link has good explanation of creating the manifest file and pulling eveything into a JAR file (I also think you must have your program as part of a Project and have the correct directory structure, such as com/foo/YourProject/ would be project of com.foo.YourProject).

    Hope that helps get you started... I eventually gave up on making my own JAR and just use Eclipse since it works 100% of the time for me lol!
    Hello and thank you for the response. I'm using netbeans and I'm able to compile then put into a JAR then run it by double clicking it without problem. This is the first program I've encountered this problem with.
    I'm gonna download eclipse (i use to use it before i started using netbeans anyways), transfer the source files and try from there.
    and if that fails I guess I'll have to try manually with a command prompt. Thank you for the assistance, will get back with any update on the issue.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Can't seem to run a JAR file by cmd line or double-click.

    Quote Originally Posted by S.Mason View Post
    It just spams the entire cmd prompt with this one line
    Java Code:
            at namesmart.NameSMART.<init>(NameSMART.java:28)
    So, what's on NameSMART.java at line 28?

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

  5. #5
    S.Mason is offline Member
    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    Default Re: Can't seem to run a JAR file by cmd line or double-click.

    Quote Originally Posted by DarrylBurke View Post
    So, what's on NameSMART.java at line 28?

    db
    Hello Darryl,

    When I got the error I went to check that exact line and there is only a bracket. This is the code thats surrounding it though, the class' constructor, some instance variables and a method.

    Java Code:
     public NameSMART() {
            
            if(checkFiles == true){
                //check for directory, load files
                new NameSMART().checkFiles();
            }
            
            initComponents();
        }
    
        DatabaseManager dbmanager;
        Boolean checkFiles = true;
        
        private void checkFiles(){
            File file = new File("ns dir");
            if(!file.exists()) {
                file.mkdir();
                File saveFile = new File(file + "\ns.dat");
                try {
                    saveFile.createNewFile();
                } catch (IOException ex) {
                    Logger.getLogger(NameSMART.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            checkFiles = false;
        }
    line 28 would be the bracket right under inItComponents(); which is a method generated by netbeans which contains all the code it generates when I use its GUI editor. Could it have something to do with the checkfiles method?


    EDIT:
    oh wow, apparently it does have something to do with that method. By removing the method, recompiling it and creating a JAR file the program runs fine by double clicking.


    EDIT:
    Yup, the source of the problem was with checkfiles method. I did a work-around that and now I can happily continue to complete this project. Thank you Darryl, really should tried to remove that method before everything else to see if that was the source of the problem.
    Last edited by S.Mason; 07-07-2012 at 11:25 PM.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Can't seem to run a JAR file by cmd line or double-click.

    You're unconditionally constructing a new NameSMART in the constructor of NameSMART, which constructs a new NameSMART, which constructs a new NameSMART, which constructs a new NameSMART, which constructs a new NameSMART ... until the program errors out on a stack overflow.

    Why did you think you needed to do that?

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

  7. #7
    S.Mason is offline Member
    Join Date
    Jul 2012
    Posts
    7
    Rep Power
    0

    Default Re: Can't seem to run a JAR file by cmd line or double-click.

    Quote Originally Posted by DarrylBurke View Post
    You're unconditionally constructing a new NameSMART in the constructor of NameSMART, which constructs a new NameSMART, which constructs a new NameSMART, which constructs a new NameSMART, which constructs a new NameSMART ... until the program errors out on a stack overflow.

    Why did you think you needed to do that?

    db
    I was trying to just see if my code for creating a directory and some files would work so I worked with the first thing that came to mind. Once I found the problem I did notice that loop in the constructor. I've set up to run from a method being called from the main method instead and seems to be working alright. Now I'm dealing with my saving/loading code which I posted in another thread.

Similar Threads

  1. Need a help on double-click jar file
    By katakali in forum New To Java
    Replies: 3
    Last Post: 07-07-2012, 11:32 PM
  2. Trying to make a jar file double click/run from desktop
    By silverglade in forum New To Java
    Replies: 6
    Last Post: 05-13-2011, 05:32 AM
  3. running jar file by double click
    By Himanshu23 in forum AWT / Swing
    Replies: 0
    Last Post: 11-11-2010, 09:24 AM
  4. Replies: 1
    Last Post: 10-30-2010, 07:27 PM
  5. Run Jar file on double click
    By dhaval.rajput.p in forum New To Java
    Replies: 2
    Last Post: 07-24-2009, 06:44 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
  •