1 2 3 Previous Next 38 Replies Latest reply: Nov 3, 2008 8:52 AM by abillconsl RSS

    Error in creating JAR file

    807589
      I have created an application and I have used JCreator to compile and run it.
      My next step is that I want to make my application as executable jar
      I did the following:
      1- I made a package name called transpackage and I have include it in each file
      2- I have executed the command : jar cfm MyJar.jar Manifest.txt transpackage/*.class
      3- Manifest.txt file contains the following line :
      Main-Class: transpackage.JavaTrans and an empty line after it.
      4- If I executed the follwing line to run the jar file:

      java -jar MyJar.jar

      I got the follwing error:

      Exception in thread "main" java.lang.NoClassDefFoundError: transpackage/JavaTran
      s com/sun/jdi/connect
      Caused by: java.lang.ClassNotFoundException: transpackage.JavaTrans com.sun.jdi.
      connect
      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)

      Please advise what the problem here is. I couldn't figure it out. Thanks for help
        • 1. Re: Error in creating JAR file
          793982
          Iman_S wrote:
          Exception in thread "main" java.lang.NoClassDefFoundError: transpackage/JavaTrans com/sun/jdi/connect
          Caused by: java.lang.ClassNotFoundException: transpackage.JavaTrans com.sun.jdi.connect
          Strange this "com/sun/jdi/connect" part, you're probably missing a classpath.
          You can add the classpath to your manifest file:
          Class-Path: /path/to/lib/jar-name.jar
          • 2. Re: Error in creating JAR file
            793982
            I see that you marked my answer as Helpful and gave me some duke starts.
            But is your problem solved? Because you didn't marked the question as answered.
            • 3. Re: Error in creating JAR file
              807589
              What I should include in the classpath? I did the following to include the classpath for the jar file, still not working

              Manifest-Version: 1.0
              Main-Class: transpackage.JavaTrans
              Class-path: C:\Documents and Settings\isz\Desktop\JavaTrans\myjar.jar

              Thanks for helping
              • 4. Re: Error in creating JAR file
                793982
                No, you don't need to include your own jar in the classpath, but the jar that contains the com.sun.jdi.connect package.
                Look the classpath used in your IDE compilation command.
                • 5. Re: Error in creating JAR file
                  807589
                  Looks like you are adding the same jar that's not going to help ....you will need to put any additional classes/jar files in the lib folder within the jar file and make this entry in the manifest file that where are the additional files. Go thru the jar file docs at [http://java.sun.com/docs/books/tutorial/deployment/jar/build.html]
                  22222222222 slow

                  Edited by: Praveen_Forum on Oct 7, 2008 6:08 PM

                  Edited by: Praveen_Forum on Oct 7, 2008 6:10 PM
                  • 6. Re: Error in creating JAR file
                    807589
                    I am really stuck, I couldn't figure out where is the package to set the path.
                    Can you advise me where I can find the package? com.sun.jdi.connect
                    Why I can run it through JCreator and can't run it in the command line?
                    Thanks for help.
                    • 7. Re: Error in creating JAR file
                      793982
                      The easiest way to learn this and find all libs used, is to study the command generated by the IDE.
                      When you run it through JCreator, the command must be shown somewhere.
                      It must have an output area, where you see your program std and err outputs. Look for the launching command, the classpath used should be there.

                      Regards,
                      Henrique Abreu
                      • 8. Re: Error in creating JAR file
                        807589
                        I have copied all the classpath in the JDK profile and set it in manifest file as below,

                        Manifest-Version: 1.0
                        Main-Class: transpackage.JavaTrans
                        Class-path: C:\Program Files\Java\jdk1.6.0_05\demo\jpda\com\sun\tools\example\debug\bdi C:\Program Files\Java\jdk1.6.0_05\demo\jpda\examples.jar C:\Program Files\Java\jdk1.6.0_05\jre\lib\ext\localedata.jar C:\Program Files\Java\jdk1.6.0_05\jre\lib\ext\sunjce_provider.jar C:\Program Files\Java\jdk1.6.0_05\jre\lib\ext\sunmscapi.jar C:\Program Files\Java\jdk1.6.0_05\jre\lib\ext\sunpkcs11.jar

                        I still got the following error:

                        Exception in thread "main" java.lang.NoClassDefFoundError: transpackage/JavaTrans
                        Caused by: java.lang.ClassNotFoundException: transpackage.JavaTrans
                        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)



                        Thanks a lot
                        • 9. Re: Error in creating JAR file
                          793982
                          At least the error slight different now.
                          Have you included the package name at the first line of your files?
                          //JavaTrans.java
                          package transpackage;
                          
                          import ...;
                          public class JavaTrans {
                              ...
                              public static void main(String[] args) {
                                  ...
                              }
                          }
                          Edited by: henrique.abreu on 08/10/2008 11:52
                          • 10. Re: Error in creating JAR file
                            807589
                            Here is the format of the JavaTrans.java I also have included the package line in all the other .java files
                            package transpackage;
                            
                            import java.io.*; 
                            import java.text.*; 
                            import java.awt.event.*;
                            .
                            public class JavaTrans  extends JFrame{
                            .
                            public  static void main(String[] args) {
                                 javax.swing.SwingUtilities.invokeLater(new Runnable() {
                                        public void run() {
                                                 JavaTrans app = new JavaTrans();     
                                                 app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                        }
                                    });                 
                                   }// End of Main
                            }// end of JavaTrans class
                            Thanks.
                            • 11. Re: Error in creating JAR file
                              807589
                              Here is a copy of my command line:
                              C:\Documents and Settings\isz\Desktop\JavaTrans>jar cvfm MyJar.jar manifest.mft transpackage\*.class
                              added manifest
                              adding: transpackage/EventThread$ThreadTrace.class(in = 5566) (out= 2396)(deflat
                              ed 56%)
                              adding: transpackage/EventThread.class(in = 9867) (out= 4114)(deflated 58%)
                              adding: transpackage/Info.class(in = 1036) (out= 484)(deflated 53%)
                              adding: transpackage/JavaTrans$1.class(in = 2531) (out= 1304)(deflated 48%)
                              adding: transpackage/JavaTrans$2.class(in = 1330) (out= 731)(deflated 45%)
                              adding: transpackage/JavaTrans$3.class(in = 611) (out= 392)(deflated 35%)
                              adding: transpackage/JavaTrans$DemoAction.class(in = 2953) (out= 1567)(deflated
                              46%)
                              adding: transpackage/JavaTrans.class(in = 36020) (out= 15723)(deflated 56%)
                              adding: transpackage/StepInfo.class(in = 1842) (out= 758)(deflated 58%)
                              adding: transpackage/StreamRedirectThread.class(in = 2308) (out= 1238)(deflated
                              46%)
                              C:\Documents and Settings\iszalans\Desktop\JavaTrans>java -jar MyJar.jar
                              Exception in thread "main" java.lang.NoClassDefFoundError: transpackage/JavaTrans
                              Caused by: java.lang.ClassNotFoundException: transpackage.JavaTrans
                              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)
                              • 12. Re: Error in creating JAR file
                                793982
                                It may sound stupid, I'm sorry, but have you recompiled after inserting the package line?
                                • 13. Re: Error in creating JAR file
                                  807589
                                  No at all thanks for helping. I have deleted the transpackage dir and compile again, still have the same problem
                                  Here is a copy for my dir that contains MyJar.jar

                                  08/10/08 18:26 <DIR> .
                                  08/10/08 18:26 <DIR> ..
                                  06/10/08 13:45 13,430 EventThread.java
                                  06/10/08 11:38 <DIR> images
                                  06/10/08 13:45 490 Info.java
                                  08/10/08 17:46 51,309 JavaTrans.java
                                  08/10/08 17:48 452 manifest.mft
                                  08/10/08 18:02 30,775 MyJar.jar
                                  06/10/08 13:45 1,223 StepInfo.java
                                  08/10/08 18:25 1,714 StreamRedirectThread.java
                                  08/10/08 18:25 <DIR> transpackage
                                  7 File(s) 99,393 bytes
                                  4 Dir(s) 133,532,831,744 bytes free

                                  Here is the created transpackage directory:

                                  08/10/08 18:25 <DIR> .
                                  08/10/08 18:25 <DIR> ..
                                  08/10/08 18:25 5,566 EventThread$ThreadTrace.class
                                  08/10/08 18:25 9,867 EventThread.class
                                  08/10/08 18:25 1,036 Info.class
                                  08/10/08 18:26 2,531 JavaTrans$1.class
                                  08/10/08 18:26 1,330 JavaTrans$2.class
                                  08/10/08 18:26 611 JavaTrans$3.class
                                  08/10/08 18:26 2,953 JavaTrans$DemoAction.class
                                  08/10/08 18:26 36,020 JavaTrans.class
                                  08/10/08 18:25 1,842 StepInfo.class
                                  08/10/08 18:26 2,308 StreamRedirectThread.class
                                  10 File(s) 64,064 bytes
                                  2 Dir(s) 133,532,766,208 bytes free

                                  I found this link for people that have the same problem, but no solution given?
                                  [http://forums.sun.com/thread.jspa?threadID=557868&start=0&tstart=0|http://forums.sun.com/thread.jspa?threadID=557868&start=0&tstart=0]
                                  • 14. Re: Error in creating JAR file
                                    800560
                                    What happens when you try the following command from the directory where you jar file is.
                                    java -cp MyJar.jar transpackage.JavaTrans
                                    If that works, then your manifest is not correct. If that does not work, you do not have the right class correctly in your jar. Try
                                    jar tf MyJar.jar
                                    and see if transpackage/JavaTrans.class shows up.

                                    Also, can you make the application work when it is not jar'ed?
                                    1 2 3 Previous Next