14 Replies Latest reply: Oct 12, 2008 12:05 PM by DarrylBurke RSS

    Error trying to run an executable Jar file

    843785
      Hi,

      I know a million people have asked this before. In the past 5 hours I have waded thru a dozen questions-answers-FAQs that were no help. So if anyone is willing to help a stupid person her is my problem:

      I developed a java program using the eclipse ide and it runs fine from within that ide.
      I packaged it into a Jar file, created a manifest file per the instructions.

      But when I double click on the jar file I get the following error from the Java Virtual Machine Loader;
      "Could not find main class. Program will exit."

      My Manifest file has the following text:

      Manifest-Version: 1.0
      Class-Path: swt.jar
      Main-Class: .graphicalUserInterface.AppStandAlone
      <blank line>

      the class AppStandAlone has the method "public static void main(String[] args) "
      it is in a package called "graphicalUserInterface".

      Any help anyone can give me would be greatly appreciated.
        • 1. Re: Error trying to run an executable Jar file
          DarrylBurke
          Main-Class: {color:red}.{color}graphicalUserInterface.AppStandAlone
          You appear to have an extra dot between the colon and the package name.

          db
          • 2. Re: Error trying to run an executable Jar file
            843785
            If I leave out the period before the package name, I don't even get an error message. Javaw.exe starts and then disappears.

            I tried using slashes instead of periods. Same error.
            I tried using backslashes. Same error.
            I tried putting .class as the end of the class file. Same error.
            I tried putting .java at the end of the class file. Same error.

            Any other suggestions would be appreciated.
            • 3. Re: Error trying to run an executable Jar file
              843785
              Java documentation says to use the "fully qualified class name". When dealing with a Jar file, just what is a "fully qualified class name"?
              • 4. Re: Error trying to run an executable Jar file
                DarrylBurke
                Javaw.exe starts and then disappears.
                Could you clarify what exactly you mean by that?

                db
                • 5. Re: Error trying to run an executable Jar file
                  DarrylBurke
                  The fully qualified class name is the package structure and the class name. In your case, graphicalUserInterface.AppStandAlone without a dot before it.

                  I have to ask now:
                  1. Does your AppStandAlone.java source code file start with the declaration
                  package graphicalUserInterface;
                  2. Is AppStandAlone.java in a folder graphicalUserInterface subordinate to the main project folder?
                  3. With a correct folder structure for your .class files, are you able to run the program from the command line using the command
                  java graphicalUserInterface.AppStandAlone
                  issued from the parent folder of the folder graphicalUserInterface that contains AppStandAlone.class?

                  db
                  • 6. Re: Error trying to run an executable Jar file
                    843785
                    BTW, Thanks for being willing to go thru this with me.

                    I double click on the .jar file and watch the windows Task Manager.
                    In the windows Task Manager, javaw.exe gets added to the list of processes but no window ever opens for it. After a second or two, javaw.exe then disappears from the Task Manager list.
                    • 7. Re: Error trying to run an executable Jar file
                      DarrylBurke
                      Ok. What about the other stuff?

                      I'm off to bed soon, it's 3:20 am in this part of the world, but hopefully someone else will step in to help here.

                      db

                      edit Additionally, are you swallowing any Exceptions in your code, with empty catch blocks? and is swt.jar in the same folder as your jar file?

                      Edited by: Darryl.Burke
                      • 8. Re: Error trying to run an executable Jar file
                        843785
                        1. Does your AppStandAlone.java source code file start with the declaration
                        package graphicalUserInterface;
                        ------ yes


                        2. Is AppStandAlone.java in a folder graphicalUserInterface subordinate to the main project folder?
                        ----- yes

                        3. With a correct folder structure for your .class files, are you able to run the program from the command line using the command
                        java graphicalUserInterface.AppStandAlone
                        issued from the parent folder of the folder graphicalUserInterface that contains AppStandAlone.class?
                        ********** when I do this I get a hard coded message I have to catch the NoClassDefFoundError
                        catch (NoClassDefFoundError e){
                             System.out.println("NoClassDefFoundError");
                        }
                        • 9. Re: Error trying to run an executable Jar file
                          843785
                          With regard to try/catch statements, none have empty catch blocks. The one I mentioned above is sequentially the first in the code.
                          • 10. Re: Error trying to run an executable Jar file
                            843785
                            I think I have an idea what is wrong.

                            I removed the try/catch statement and got the full Java error trail. Looks like I am missing a class-path.
                            • 11. Re: Error trying to run an executable Jar file
                              843785
                              Another 3 hours spent trying to run this java application in a Jar file.

                              I identified that I did not have all class paths specified. So I tried to enter them in the "Class-Path:" line of the manifest file. But, according to the java tutorial, the syntax in a manifest file for classpaths is a space SEPARATING each path name. I have a space IN the path name and java is not understanding the paths correctly. For instance, I have a classpath c:\Progran Files\Java\etc... and java interprets this to be a classpath c:\Progran with Files\Java\etc as the program I want to run.

                              I tried enclosing the paths in double quotes. Didn't work
                              I tried enclosing the paths in single quotes. Didn't work
                              I tried using a semicolon as a separator with double quotes. Didn't work
                              I tried using a semicolon as a separator with single quotes. Didn't work
                              I tried using a semicolon as a separator with no quotes. Didn't work

                              I removed the "Class-Path:" line from the manifest and tried adding -cp param to the java command. Example:

                              java -cp %classpath% -jar myapp.jar

                              I tried all the variations above in the -cp param. None of them worked.

                              The only thing that works is if I move executable jar file to the same directory as the required libraries. Then I specify a "Class-Path:" line with no spaces in the path names. Obviously this is not a permanent solution.

                              If anyone else has the patience to help me I would really appreciate it.
                              • 12. Re: Error trying to run an executable Jar file
                                DarrylBurke
                                Don't use absolute paths in a jar manifest's class-path entry. Here read this:
                                [http://mindprod.com/jgloss/jar.html#CLASSPATH]

                                Wouldn't hurt to read the rest of that page too.

                                db
                                • 13. Re: Error trying to run an executable Jar file
                                  843785
                                  Thankyou for that URL. I have not yet ried it but it clearly addresses the issues I am having.

                                  This issue reminds me of the attitude of a senior developer I once worked for. "Its not bad architecture. Its a feature!"
                                  • 14. Re: Error trying to run an executable Jar file
                                    DarrylBurke
                                    Umm, I consider it more like "Work with what you've got, not against it."

                                    db