5 Replies Latest reply on Jul 8, 2001 9:48 AM by 798701

    Cant get JAR file to execute

    807592
      I'm developing an application in using JDK 1.2.1 and Borland/Inprise's JBuilder Professional version 3.0 (the OS is MS windows 98).

      My program is an application , not an applet.

      My program runs OK from the jbuilder development environment, but now I want it standalone , as a .JAR file. Using jbuilders deployment wizard, I've created a .JAR file for my program ("untitled2.jar).
      It includes a manifest.

      I set up a test subdirectory c:\test and copied all the files from c:\program files\javasoft\jre\1.2\bin (which includes java.exe and javaw.exe). I then copied untitled2.jar to c:\test

      I've looked in books & searched on the web site and I've tried various permutations of the syntax. For example I tried :

      java -jar -cp c:\test untitled2.jar

      but get the error message:

      "Failed to load Main-Class manifest attribute from untitled2.jar"


      Have I just got the syntax wrong or am I missing something else?

      Also do I understand right that JRE.EXE has been replaced with JAVA.EXE (and JREW.EXE with JAVAW.EXE) ?


      thanks in advance for any help

      Mike
        • 1. Re: Cant get JAR file to execute
          807592
          1. You don't really need to copy stuff out of the jre. Directly from the jre you can execute java.exe.

          2. Your dont need the -jar

          3. Looks like you named your jar in the commandline, but not the class you actually want to execute.

          Try

          java -cp c:\test\untitled2.jar MyClassWithMain

          (Substitute the name of the class which has your main method)
          • 2. Re: Cant get JAR file to execute
            807592
            Hi,

            Your syntax was correct but you need to check wether your MANIFEST.MF resides in the directory META-INF in the .jar file.

            You also need to check wether this MANIFEST.MF contains a line like

            Main-Class: my.main

            Note that everything is case-sensitive!

            And about your question wether jre.exe is replaced with java.exe: this is indeed true.

            Regards,

            Kurt.
            • 3. Re: Cant get JAR file to execute
              798701
              try to check that you really have the manifest file with: jar -t untitled2.jar
              If it does have it, are you sure you have the line "Main-Class: classname" in it?

              Running the jar file can then be done with java -jar untitled2.jar
              • 4. Re: Cant get JAR file to execute
                807592
                Thanks for the replies. I tried what you said :

                I've replaced "untitled2.jar" with "loofabtest.jar" (actual name of the program)
                The program is 2 java source files (loofabtest.java and frame1.java) , the main file is contained in
                public class loofabtest within in loofabtest.java. The JAR file created is called loofabtest.jar

                As I said previously the program runs OK from within jbuilder. All files & class names are lower case.

                I used winzip (version 7.0) to open loofabtest.jar.
                When I open loofabtest.jar there is a file called Manifest.mf with a path:

                meta-inf\

                when I open that there is NO line

                Main-Class: my.main or similar

                So I edit the Manifest.mf file & added a line :

                Main-Class: loofabtest

                Query 1: is this syntax right or should the line read: Main-Class: loofabtest.class

                after editing the file , when I save it I get an overwrite option , if I say no , I end up with 2 manifest files (which I think wont work) If I yes to overwrite , the file loses the
                meta-inf\     
                path (i.e. there is no path)
                I tried editing the manifest in jbuilder , but with no luck (jbuilder autogenerates the manifest)

                I also tried extracting all the files in the JAR , editing the manifest , then rearchiving them. I get the error message

                java.io.IOException: invalid manifest format
                at java.util.jar.Manifest.read(Compiled Code)
                at java.util.jar.Manifest.<init>(Manifest.java:55)
                at sun.tools.jar.Main.run(Main.java:87)
                at sun.tools.jar.Main.main(Main.java:760)


                Query 2 : Is there an easy way to edit the manifest file to add the line needed and keep the meta-inf\ path?

                • 5. Re: Cant get JAR file to execute
                  798701
                  Use the "jar" command line tool distributed with the JDK:
                  jar vcmf manifest.txt loofabtest.jar loofabtest.class frame1.class
                  The file manifest.txt should have the text "Main-Class: loofabtest" and a line break. DON'T forget the line break!