4 Replies Latest reply: Feb 6, 2010 5:31 AM by DarrylBurke RSS

    export jar with external libraries

    843804
      I wrote a small application file convertor that takes two parameters a file as an input and another filename as an output. in eclipse, i export a jar, select my package and give it my own manifest file to specify the external jar i use. The manifest file i use is:
      Manifest-Version: 1.0
      Main-Class: test.ModelConvertor
      Class-Path: C:\Program Files\Java\com\mnstarfire\loaders3d
      When i run java -jar Model.jar in the command prompt (windows), it starts to run the application then i get a NoClassDefFoundError error for my external jar i'm using (located at: C:\Program Files\Java\com\mnstarfire\loaders3d\StarfireExt.jar)

      When i run java -jar Model.jar on my unix environment, i get:
      Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: test.ModelConvertor
         at java.lang.VMClassLoader.transformException(java.lang.Class, java.lang.Throwable) (/usr/lib64/libgcj.so.6.0.0)
         at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib64/libgcj.so.6.0.0)
         at java.lang.Class.initializeClass() (/usr/lib64/libgcj.so.6.0.0)
         at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib64/libgcj.so.6.0.0)
         at gnu.java.lang.MainThread.run() (/usr/lib64/libgcj.so.6.0.0)
      Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:Model.jar,file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
         at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib64/libgcj.so.6.0.0)
         at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib64/libgcj.so.6.0.0)
         at java.lang.ClassLoader.loadClass(java.lang.String) (/usr/lib64/libgcj.so.6.0.0)
         at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib64/libgcj.so.6.0.0)
         ...4 more
      I've been trying to find a solution for this for a few hours now. I have no clue what i'm doing wrong. Any help would be appreciated.
        • 1. Re: export jar with external libraries
          843804
          i fixed the first problem, it turns out the class path should point to the actual jar, not the directory that contains it. it now runs correctly in command prompt (windows). when i copy the jar to my unix environment, i get a worse error:
          [landon.silla@mordor pointCloud]$ java -jar Model.jar
          Exception in thread "main" java.lang.NoClassDefFoundError: while resolving class: test.ModelConvertor
             at java.lang.VMClassLoader.transformException(java.lang.Class, java.lang.Throwable) (/usr/lib64/libgcj.so.6.0.0)
             at java.lang.VMClassLoader.resolveClass(java.lang.Class) (/usr/lib64/libgcj.so.6.0.0)
             at java.lang.Class.initializeClass() (/usr/lib64/libgcj.so.6.0.0)
             at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib64/libgcj.so.6.0.0)
             at gnu.java.lang.MainThread.run() (/usr/lib64/libgcj.so.6.0.0)
          Caused by: java.lang.ClassNotFoundException: java.lang.StringBuilder not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:Model.jar,file:./], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
             at java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib64/libgcj.so.6.0.0)
             at java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib64/libgcj.so.6.0.0)
             at java.lang.ClassLoader.loadClass(java.lang.String) (/usr/lib64/libgcj.so.6.0.0)
             at java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib64/libgcj.so.6.0.0)
             ...4 more
          how can it not find test.ModelConvertor? what do i need to set?
          • 2. Re: export jar with external libraries
            843804
            I don't know the solution of your concrete problem.
            But it's not right to have an absolute path in a manifest class-path attribute. Use relative path instead.
            • 3. Re: export jar with external libraries
              843804
              The class-path header expects an URL. The URL can be both relative and absolute. You have supplied an absolute file path, not an URL
              • 4. Re: export jar with external libraries
                DarrylBurke
                kengu, welcome to the forum. Please don't post in threads that are long dead. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.

                I'm locking this thread now.

                db