5 Replies Latest reply: Jul 4, 2011 9:08 AM by gimbal2 RSS

    create an executable jar file

    809490
      Hello

      I implemented an application and now i want to distribute the application by creating an executable jar file, but there is a problem with the classpath i think.
      The application uses several properties files, several image files and two dependant jar files. There is no error with the properties or image files.
      With this command i create the jar file:
      jar cvfm iz.jar Manifest.txt com 1280x800Input.properties 1920x1080Input.properties inzdb_test2_nofire.properties inzdb_test2_fire.properties inzdb_test_nofire.properties inzdb_test_fire.properties inzdb_strato.properties inzdb.properties inzdb_local.properties med.png hand.png Inzeit.jpg hotel.jpg mysql-connector-java-5.1.13-bin.jar jaybird-full-2.1.6.jar
      
       
      pause
      The Manifest.txt looks like this.
      Main-Class: com.inzeit.dbview.TableView
      Class-Path: mysql-connector-java-5.1.13-bin.jar jaybird-full-2.1.6.jar
      No when i run the iz.jar file with
      java -jar iz.jar
      the error i get is:
      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)
      I thought the classpath is set properly in the Manifest file, but there seems to be some error.
      I hope someone knows what to do here.

      Kind regards,
      Chang
        • 1. Re: create an executable jar file
          EJP
          Class-Path: mysql-connector-java-5.1.13-bin.jar jaybird-full-2.1.6.jar
          That says that these two jars should be loaded and that they are in the same directory as the JAR file that contains this Manifest.

          Are they?
          • 2. Re: create an executable jar file
            809490
            Hello EJP.

            Thanks for your help. No they are not in the same directory, because i want the jaybird-full-2.1.6.jar and the mysql-connector-java-5.1.13-bin.jar to be in the jar file. So I can simply start the application by double clicking on the iz.jar without other dependencies.
            How can I achieve this?

            regards,
            Chang
            • 3. Re: create an executable jar file
              EJP
              No they are not in the same directory
              So that's why it doesn't work, because your Manifest's Class-path entry says that they are.
              because i want the jaybird-full-2.1.6.jar and the mysql-connector-java-5.1.13-bin.jar to be in the jar
              Not possible until JDK 1.7.
              • 4. Re: create an executable jar file
                872853
                EJP is correct when you specify classpath inside manifest file , it starts from same directory where jar file is present. you may find this link interesting http://javarevisited.blogspot.com/2011/01/how-classpath-work-in-java.html.

                As far as your second questions goes I don't think there is any way you can embed jar into another jar, my suggestion is create a bash script or dos script to run the program .
                • 5. Re: create an executable jar file
                  gimbal2
                  869850 wrote:
                  As far as your second questions goes I don't think there is any way you can embed jar into another jar, my suggestion is create a bash script or dos script to run the program .
                  That doesn't change anything. If the class-path line in the manifest is wrong the application will still fail to run.

                  The only option you would have is to not treat the jar as an executable jar but in stead execute the main class in it and specify the classpath yourself... why bother if you can just put the libraries in the proper place? This is a simple matter of fixing your build script and/or installation method, not to workaround a mistake being made somewhere.