Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java - Problem with Jar

  • 03-12-2008 10:18am
    #1
    Registered Users, Registered Users 2 Posts: 196 ✭✭


    I finished developing a program in the Eclipse IDE, so I exported it to a Jar file. My computer intially opened up the Jar file using winzip, so i changed the default program to open it with to Java (TM) Platform SE Binary.
    Now when I double click on the icon, the timer glass shows for about 1-2 seconds and then thats it, nothing else happens. I can't get my program to open up outside of my IDE.

    If anyone could help I would greatly appreciate it.

    Thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    what do you get when you run it from the command line?


  • Registered Users, Registered Users 2 Posts: 2,013 ✭✭✭lynchie


    juror wrote: »
    I finished developing a program in the Eclipse IDE, so I exported it to a Jar file. My computer intially opened up the Jar file using winzip, so i changed the default program to open it with to Java (TM) Platform SE Binary.
    Now when I double click on the icon, the timer glass shows for about 1-2 seconds and then thats it, nothing else happens. I can't get my program to open up outside of my IDE.

    If anyone could help I would greatly appreciate it.

    Thanks.

    Its not going to run by double clicking on it without adding a Main-Class element to the manifest file before exporting it as a jar file.


  • Registered Users, Registered Users 2 Posts: 196 ✭✭juror


    I ran it from the command line, and again nothing happens. The command prompt just re-appears.

    I set the entry point in Eclipse. This was done in the Exporting wizard. It resulted in the following Mainfest file being generated and included in the jar,
    Manifest-Version: 1.0
    Main-Class: gui.Main
    


  • Registered Users, Registered Users 2 Posts: 2,013 ✭✭✭lynchie


    What are the contents of the jar file. I assume your main class is called Main.class and its in the gui package? If so, the contents of the jar file should be similar to the following

    jar -tvf myjar.jar
    xxx xxx xxx xxx xx xx xx META-INF/manifest.mf
    xxx xxx xxx xxx xx xx xx gui/Main.class
    


  • Registered Users, Registered Users 2 Posts: 197 ✭✭pauldiv


    Sounds like a bad build. If you have Netbeans you could try importing the project, clean and rebuild it. Netbeans then creates a deployment directory under the main project folder that includes java libs, a manifest and an executable jar etc. It works a treat.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 196 ✭✭juror


    pauldiv wrote: »
    Sounds like a bad build. If you have Netbeans you could try importing the project, clean and rebuild it. Netbeans then creates a deployment directory under the main project folder that includes java libs, a manifest and an executable jar etc. It works a treat.


    I just tried that, but I have gotten the same result.
    I do use a mysql connector, would this have anything to do with it?


  • Registered Users, Registered Users 2 Posts: 196 ✭✭juror


    If this helps, I had been running it from the command line by simply typing the name of the jar
    RecycleProgram1.jar
    

    But recently i tried this
    java -jar RecycleProgram1.jar
    

    and the follwing exception occurred
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at database.DatabseConnection.createDBConnection(DatabseConnection.java:30)
            at database.DatabaseController.<init>(DatabaseController.java:91)
            at database.DatabaseController.<clinit>(DatabaseController.java:86)
            at gui.Main.loadData(Main.java:26)
            at gui.Main.<init>(Main.java:18)
            at gui.Main.main(Main.java:37)
    Exception in thread "main" java.lang.ExceptionInInitializerError
            at gui.Main.loadData(Main.java:26)
            at gui.Main.<init>(Main.java:18)
            at gui.Main.main(Main.java:37)
    Caused by: java.lang.NullPointerException
            at database.DatabaseController.createStatements(DatabaseController.java:105)
            at database.DatabaseController.<init>(DatabaseController.java:92)
            at database.DatabaseController.<clinit>(DatabaseController.java:86)
            ... 3 more
     
    

    Might this mean there is something missing from my Manifest file in realtion to the DB driver?


  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    you need the classpath to your mySQL set up on the machine so that it can see the related jar files for that.

    Your not going to be able to make a self executing jar file. But you can make a CMD/SH file file and run that.

    will be something like...

    java -cp <path to required jars> -jar RecycleProgram1.jar


  • Registered Users, Registered Users 2 Posts: 196 ✭✭juror


    Hobbes wrote: »
    you need the classpath to your mySQL set up on the machine so that it can see the related jar files for that.

    Your not going to be able to make a self executing jar file. But you can make a CMD/SH file file and run that.

    will be something like...

    java -cp <path to required jars> -jar RecycleProgram1.jar


    Brilliant! It works. Thanks very much for the help, and to everyone else who contributed.

    I created a .bat file to run the command above and it worked a treat.
    Thanks again


Advertisement