You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Rob Tanner <ca...@gmail.com> on 2013/06/18 00:38:58 UTC

Access jar files in a library directory in the jar file

Hi,

I'm trying to build a runnable jar file that includes several libraries that are also jar files.  My problem is that Java does not seem to be able to find the libraries.  I get this message when I try to run the jar file:

java -jar LibraryAlmaInterface.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/linfield/PreferencesManager/XMLPrefs
        at org.linfield.Library.PatronDataTransfer.<clinit>(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.linfield.PreferencesManager.XMLPrefs
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 1 more

You can see from the table of contents that the c;ass file is there:

jar tf LibraryAlmaInterface.jar
META-INF/
META-INF/MANIFEST.MF
lib/
org/
org/linfield/
org/linfield/Library/
org/linfield/Library/Workers/
lib/jsch-0.1.49.jar
lib/linfield.jar
lib/log4j-1.2.15.jar
lib/xerces.jar
org/linfield/Library/CalculateBarcode.class
org/linfield/Library/PatronDataTransfer.class
org/linfield/Library/Workers/MyUserInfo.class
org/linfield/Library/Workers/PatronLoadsXML.class
org/linfield/Library/Workers/SecureFTPHandler.class

And the linfield.jar contains the class that the loader can't find:

META-INF/
META-INF/MANIFEST.MF
org/
org/linfield/
org/linfield/PreferencesManager/
org/linfield/PreferencesManager/PreferencesParser.class
org/linfield/PreferencesManager/XMLPrefs.class
org/linfield/PreferencesManager/XMLPrefs.java
org/linfield/PreferencesManager/PreferencesParser.java

And the manifest in linfield.jar is:

cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.4.0 (Sun Microsystems Inc.)

And most importantly, here is the main MANIFEST.MF file (for LibraryAlmaInterface.jar):

cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_45-b06-451-11M4406 (Apple Inc.)
Built-By: rtanner
Main-Class: org.linfield.Library.PatronDataTransfer
Class-Path: lib/jsch-0.1.49.jar lib/linfield.jar lib/log4j-1.2.15.jar 
 lib/xerces.jar


I'm assuming that the problem is with the manifest, but I have no idea what it is.  Any help would be greatly appreciated.

Thanks,


Rob Tanner
Linfield College





Re: Access jar files in a library directory in the jar file

Posted by Rob Seegel <Ro...@comcast.net>.
Rob,

   There are various open source solutions out there to do what you're 
looking for, but there is no "built-in" way to do what you want to do 
using plain Java. I saw someone else suggest one-jar which is what I 
would have suggested, too. There is another one called Meta Jar that 
basically does the same thing. (http://www.yagga.net/java/metajar/ )

Rob

On 6/17/13 6:38 PM, Rob Tanner wrote:
> Hi,
>
> I'm trying to build a runnable jar file that includes several libraries that are also jar files.  My problem is that Java does not seem to be able to find the libraries.  I get this message when I try to run the jar file:
>
> java -jar LibraryAlmaInterface.jar
> Exception in thread "main" java.lang.NoClassDefFoundError: org/linfield/PreferencesManager/XMLPrefs
>          at org.linfield.Library.PatronDataTransfer.<clinit>(Unknown Source)
> Caused by: java.lang.ClassNotFoundException: org.linfield.PreferencesManager.XMLPrefs
>          at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>          at java.security.AccessController.doPrivileged(Native Method)
>          at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>          at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
>          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>          at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
>          ... 1 more
>
> You can see from the table of contents that the c;ass file is there:
>
> jar tf LibraryAlmaInterface.jar
> META-INF/
> META-INF/MANIFEST.MF
> lib/
> org/
> org/linfield/
> org/linfield/Library/
> org/linfield/Library/Workers/
> lib/jsch-0.1.49.jar
> lib/linfield.jar
> lib/log4j-1.2.15.jar
> lib/xerces.jar
> org/linfield/Library/CalculateBarcode.class
> org/linfield/Library/PatronDataTransfer.class
> org/linfield/Library/Workers/MyUserInfo.class
> org/linfield/Library/Workers/PatronLoadsXML.class
> org/linfield/Library/Workers/SecureFTPHandler.class
>
> And the linfield.jar contains the class that the loader can't find:
>
> META-INF/
> META-INF/MANIFEST.MF
> org/
> org/linfield/
> org/linfield/PreferencesManager/
> org/linfield/PreferencesManager/PreferencesParser.class
> org/linfield/PreferencesManager/XMLPrefs.class
> org/linfield/PreferencesManager/XMLPrefs.java
> org/linfield/PreferencesManager/PreferencesParser.java
>
> And the manifest in linfield.jar is:
>
> cat META-INF/MANIFEST.MF
> Manifest-Version: 1.0
> Created-By: 1.4.0 (Sun Microsystems Inc.)
>
> And most importantly, here is the main MANIFEST.MF file (for LibraryAlmaInterface.jar):
>
> cat META-INF/MANIFEST.MF
> Manifest-Version: 1.0
> Ant-Version: Apache Ant 1.8.3
> Created-By: 1.6.0_45-b06-451-11M4406 (Apple Inc.)
> Built-By: rtanner
> Main-Class: org.linfield.Library.PatronDataTransfer
> Class-Path: lib/jsch-0.1.49.jar lib/linfield.jar lib/log4j-1.2.15.jar
>   lib/xerces.jar
>
>
> I'm assuming that the problem is with the manifest, but I have no idea what it is.  Any help would be greatly appreciated.
>
> Thanks,
>
>
> Rob Tanner
> Linfield College
>
>
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Access jar files in a library directory in the jar file

Posted by Bruce Atherton <br...@callenish.com>.
Oops. I meant Rob, of course.

On 18/06/2013 4:34 PM, Bruce Atherton wrote:
> You are right that it is inefficient, but it is easy to understand. If 
> you want to get efficient, you could create the main.jar with 
> inclusions of <zipfileset>[1] using the src attribute for the other jars.
>
> As for the manifest, while this would be tricky for a general purpose 
> jar merging tool, it isn't a problem when you are creating a specific 
> JAR file. Presumably Earl knows what the combined manifest should look 
> like.
>
> [1] http://ant.apache.org/manual/Types/zipfileset.html
>
> On 18/06/2013 11:53 AM, Earl Hood wrote:
>> On Tue, Jun 18, 2013 at 11:54 AM, Bruce Atherton wrote:
>>> It is fairly trivial to do. In your main jar target:
>>>
>>>      1. create a temporary directory
>>>      2. run the unjar task
>>>      3. jar up your main jar, including the contents of the temporary
>>> directory
>>>      4. delete the temporary directory
>> That is a way to do it, but it is inefficient and does not deal with
>> manifest entries (which may or may not matter depending on your needs).
>>
>> Many moons ago, I wrote a java program to do jar merging, where it
>> supports inclusion and exclusion expressions (so you can merge subsets
>> of a jars) and attempts to also merge manifest entry information.  The
>> program is efficient in that it does not pre-extract the jar files, but
>> instead walks the jar structure when doing the merge.
>>
>> Never made it into an Ant task.  When I do need it, I just use the
>> <java> task to call it.
>>
>> IIRC, at the time (many years ago) there was not much interest in such a
>> facility of merging jars so I never packaged it up as an OSS project.
>>
>> --ewh
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Access jar files in a library directory in the jar file

Posted by Bruce Atherton <br...@callenish.com>.
You are right that it is inefficient, but it is easy to understand. If 
you want to get efficient, you could create the main.jar with inclusions 
of <zipfileset>[1] using the src attribute for the other jars.

As for the manifest, while this would be tricky for a general purpose 
jar merging tool, it isn't a problem when you are creating a specific 
JAR file. Presumably Earl knows what the combined manifest should look like.

[1] http://ant.apache.org/manual/Types/zipfileset.html

On 18/06/2013 11:53 AM, Earl Hood wrote:
> On Tue, Jun 18, 2013 at 11:54 AM, Bruce Atherton wrote:
>> It is fairly trivial to do. In your main jar target:
>>
>>      1. create a temporary directory
>>      2. run the unjar task
>>      3. jar up your main jar, including the contents of the temporary
>> directory
>>      4. delete the temporary directory
> That is a way to do it, but it is inefficient and does not deal with
> manifest entries (which may or may not matter depending on your needs).
>
> Many moons ago, I wrote a java program to do jar merging, where it
> supports inclusion and exclusion expressions (so you can merge subsets
> of a jars) and attempts to also merge manifest entry information.  The
> program is efficient in that it does not pre-extract the jar files, but
> instead walks the jar structure when doing the merge.
>
> Never made it into an Ant task.  When I do need it, I just use the
> <java> task to call it.
>
> IIRC, at the time (many years ago) there was not much interest in such a
> facility of merging jars so I never packaged it up as an OSS project.
>
> --ewh
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Access jar files in a library directory in the jar file

Posted by Earl Hood <ea...@gmail.com>.
On Tue, Jun 18, 2013 at 11:54 AM, Bruce Atherton wrote:
> It is fairly trivial to do. In your main jar target:
>
>     1. create a temporary directory
>     2. run the unjar task
>     3. jar up your main jar, including the contents of the temporary
> directory
>     4. delete the temporary directory

That is a way to do it, but it is inefficient and does not deal with
manifest entries (which may or may not matter depending on your needs).

Many moons ago, I wrote a java program to do jar merging, where it
supports inclusion and exclusion expressions (so you can merge subsets
of a jars) and attempts to also merge manifest entry information.  The
program is efficient in that it does not pre-extract the jar files, but
instead walks the jar structure when doing the merge.

Never made it into an Ant task.  When I do need it, I just use the
<java> task to call it.

IIRC, at the time (many years ago) there was not much interest in such a
facility of merging jars so I never packaged it up as an OSS project.

--ewh

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Access jar files in a library directory in the jar file

Posted by Bruce Atherton <br...@callenish.com>.
It is fairly trivial to do. In your main jar target:

     1. create a temporary directory
     2. run the unjar task
     3. jar up your main jar, including the contents of the temporary 
directory
     4. delete the temporary directory

See http://ant.apache.org/manual/Tasks/unzip.html for docs on the unjar 
task.

On 18/06/2013 12:27 AM, Rob Tanner wrote:
> In that case, is there an ant task that will enable me to explode the jar file and add the classes that way.  I could simply explode the jars in my development hierarchy in Eclipse, but I would rather leave them untouched there and only explode them when I build the main jar file.  I looked in the ant user's guide, and I couldn't find such a task, but is there a way to execute a short shell script from within the build.xml file?
>
> ~ Rob
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Access jar files in a library directory in the jar file

Posted by Rob Tanner <ca...@gmail.com>.
In that case, is there an ant task that will enable me to explode the jar file and add the classes that way.  I could simply explode the jars in my development hierarchy in Eclipse, but I would rather leave them untouched there and only explode them when I build the main jar file.  I looked in the ant user's guide, and I couldn't find such a task, but is there a way to execute a short shell script from within the build.xml file?

~ Rob





On Jun 17, 2013, at 4:08 PM, Joe Attardi <jo...@attardi.net> wrote:

> Hi Rob,
> 
> I don't think you can have JAR files inside the JAR file like that.
> 
> 
> On Mon, Jun 17, 2013 at 6:38 PM, Rob Tanner <ca...@gmail.com> wrote:
> 
>> Hi,
>> 
>> I'm trying to build a runnable jar file that includes several libraries
>> that are also jar files.  My problem is that Java does not seem to be able
>> to find the libraries.  I get this message when I try to run the jar file:
>> 
>> java -jar LibraryAlmaInterface.jar
>> Exception in thread "main" java.lang.NoClassDefFoundError:
>> org/linfield/PreferencesManager/XMLPrefs
>>        at org.linfield.Library.PatronDataTransfer.<clinit>(Unknown Source)
>> Caused by: java.lang.ClassNotFoundException:
>> org.linfield.PreferencesManager.XMLPrefs
>>        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>>        at java.security.AccessController.doPrivileged(Native Method)
>>        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>>        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
>>        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>>        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
>>        ... 1 more
>> 
>> You can see from the table of contents that the c;ass file is there:
>> 
>> jar tf LibraryAlmaInterface.jar
>> META-INF/
>> META-INF/MANIFEST.MF
>> lib/
>> org/
>> org/linfield/
>> org/linfield/Library/
>> org/linfield/Library/Workers/
>> lib/jsch-0.1.49.jar
>> lib/linfield.jar
>> lib/log4j-1.2.15.jar
>> lib/xerces.jar
>> org/linfield/Library/CalculateBarcode.class
>> org/linfield/Library/PatronDataTransfer.class
>> org/linfield/Library/Workers/MyUserInfo.class
>> org/linfield/Library/Workers/PatronLoadsXML.class
>> org/linfield/Library/Workers/SecureFTPHandler.class
>> 
>> And the linfield.jar contains the class that the loader can't find:
>> 
>> META-INF/
>> META-INF/MANIFEST.MF
>> org/
>> org/linfield/
>> org/linfield/PreferencesManager/
>> org/linfield/PreferencesManager/PreferencesParser.class
>> org/linfield/PreferencesManager/XMLPrefs.class
>> org/linfield/PreferencesManager/XMLPrefs.java
>> org/linfield/PreferencesManager/PreferencesParser.java
>> 
>> And the manifest in linfield.jar is:
>> 
>> cat META-INF/MANIFEST.MF
>> Manifest-Version: 1.0
>> Created-By: 1.4.0 (Sun Microsystems Inc.)
>> 
>> And most importantly, here is the main MANIFEST.MF file (for
>> LibraryAlmaInterface.jar):
>> 
>> cat META-INF/MANIFEST.MF
>> Manifest-Version: 1.0
>> Ant-Version: Apache Ant 1.8.3
>> Created-By: 1.6.0_45-b06-451-11M4406 (Apple Inc.)
>> Built-By: rtanner
>> Main-Class: org.linfield.Library.PatronDataTransfer
>> Class-Path: lib/jsch-0.1.49.jar lib/linfield.jar lib/log4j-1.2.15.jar
>> lib/xerces.jar
>> 
>> 
>> I'm assuming that the problem is with the manifest, but I have no idea
>> what it is.  Any help would be greatly appreciated.
>> 
>> Thanks,
>> 
>> 
>> Rob Tanner
>> Linfield College
>> 
>> 
>> 
>> 
>> 
> 
> 
> -- 
> *Joe Attardi*
> joe@attardi.net


Re: Access jar files in a library directory in the jar file

Posted by Raja Nagendra Kumar <na...@tejasoft.com>.
Hi,

http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

If you want to load classes inMyUtils.jarinto the class path for use 
inMyJar.jar. These two JAR files are in the same directory and can't be 
packaged within MyJar.jar

Regards,
Nagendra
*Raja Nagendra Kumar*
Founder & C.T.O 	
*Mobile:* +91-9886723872
	*Email:* nagendra.raja@tejasoft.com <ma...@tejasoft.com>
*IM:* nagendra.raja (Skype)
*http://in.linkedin.com/in/nagkumar*
	*TejaSoft Innovations Pvt Ltd*
<http://www.tejasoft.com>
Factor 4 Results

See who we know in common 
<http://www.linkedin.com/e/wwk/5094208/?hs=false&tok=0bfzEZotG8slI1> 
Want a signature like this? 
<http://www.linkedin.com/e/sig/5094208/?hs=false&tok=0uLVu92uq8slI1>


On 6/18/2013 4:38 AM, Joe Attardi wrote:
> Hi Rob,
>
> I don't think you can have JAR files inside the JAR file like that.
>
>
> On Mon, Jun 17, 2013 at 6:38 PM, Rob Tanner<ca...@gmail.com>  wrote:
>
>> Hi,
>>
>> I'm trying to build a runnable jar file that includes several libraries
>> that are also jar files.  My problem is that Java does not seem to be able
>> to find the libraries.  I get this message when I try to run the jar file:
>>
>> java -jar LibraryAlmaInterface.jar
>> Exception in thread "main" java.lang.NoClassDefFoundError:
>> org/linfield/PreferencesManager/XMLPrefs
>>          at org.linfield.Library.PatronDataTransfer.<clinit>(Unknown Source)
>> Caused by: java.lang.ClassNotFoundException:
>> org.linfield.PreferencesManager.XMLPrefs
>>          at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>>          at java.security.AccessController.doPrivileged(Native Method)
>>          at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>>          at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
>>          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>>          at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
>>          ... 1 more
>>
>> You can see from the table of contents that the c;ass file is there:
>>
>> jar tf LibraryAlmaInterface.jar
>> META-INF/
>> META-INF/MANIFEST.MF
>> lib/
>> org/
>> org/linfield/
>> org/linfield/Library/
>> org/linfield/Library/Workers/
>> lib/jsch-0.1.49.jar
>> lib/linfield.jar
>> lib/log4j-1.2.15.jar
>> lib/xerces.jar
>> org/linfield/Library/CalculateBarcode.class
>> org/linfield/Library/PatronDataTransfer.class
>> org/linfield/Library/Workers/MyUserInfo.class
>> org/linfield/Library/Workers/PatronLoadsXML.class
>> org/linfield/Library/Workers/SecureFTPHandler.class
>>
>> And the linfield.jar contains the class that the loader can't find:
>>
>> META-INF/
>> META-INF/MANIFEST.MF
>> org/
>> org/linfield/
>> org/linfield/PreferencesManager/
>> org/linfield/PreferencesManager/PreferencesParser.class
>> org/linfield/PreferencesManager/XMLPrefs.class
>> org/linfield/PreferencesManager/XMLPrefs.java
>> org/linfield/PreferencesManager/PreferencesParser.java
>>
>> And the manifest in linfield.jar is:
>>
>> cat META-INF/MANIFEST.MF
>> Manifest-Version: 1.0
>> Created-By: 1.4.0 (Sun Microsystems Inc.)
>>
>> And most importantly, here is the main MANIFEST.MF file (for
>> LibraryAlmaInterface.jar):
>>
>> cat META-INF/MANIFEST.MF
>> Manifest-Version: 1.0
>> Ant-Version: Apache Ant 1.8.3
>> Created-By: 1.6.0_45-b06-451-11M4406 (Apple Inc.)
>> Built-By: rtanner
>> Main-Class: org.linfield.Library.PatronDataTransfer
>> Class-Path: lib/jsch-0.1.49.jar lib/linfield.jar lib/log4j-1.2.15.jar
>>   lib/xerces.jar
>>
>>
>> I'm assuming that the problem is with the manifest, but I have no idea
>> what it is.  Any help would be greatly appreciated.
>>
>> Thanks,
>>
>>
>> Rob Tanner
>> Linfield College
>>
>>
>>
>>
>>
>

Re: Access jar files in a library directory in the jar file

Posted by Joe Attardi <jo...@attardi.net>.
Hi Rob,

I don't think you can have JAR files inside the JAR file like that.


On Mon, Jun 17, 2013 at 6:38 PM, Rob Tanner <ca...@gmail.com> wrote:

> Hi,
>
> I'm trying to build a runnable jar file that includes several libraries
> that are also jar files.  My problem is that Java does not seem to be able
> to find the libraries.  I get this message when I try to run the jar file:
>
> java -jar LibraryAlmaInterface.jar
> Exception in thread "main" java.lang.NoClassDefFoundError:
> org/linfield/PreferencesManager/XMLPrefs
>         at org.linfield.Library.PatronDataTransfer.<clinit>(Unknown Source)
> Caused by: java.lang.ClassNotFoundException:
> org.linfield.PreferencesManager.XMLPrefs
>         at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
>         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
>         at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
>         ... 1 more
>
> You can see from the table of contents that the c;ass file is there:
>
> jar tf LibraryAlmaInterface.jar
> META-INF/
> META-INF/MANIFEST.MF
> lib/
> org/
> org/linfield/
> org/linfield/Library/
> org/linfield/Library/Workers/
> lib/jsch-0.1.49.jar
> lib/linfield.jar
> lib/log4j-1.2.15.jar
> lib/xerces.jar
> org/linfield/Library/CalculateBarcode.class
> org/linfield/Library/PatronDataTransfer.class
> org/linfield/Library/Workers/MyUserInfo.class
> org/linfield/Library/Workers/PatronLoadsXML.class
> org/linfield/Library/Workers/SecureFTPHandler.class
>
> And the linfield.jar contains the class that the loader can't find:
>
> META-INF/
> META-INF/MANIFEST.MF
> org/
> org/linfield/
> org/linfield/PreferencesManager/
> org/linfield/PreferencesManager/PreferencesParser.class
> org/linfield/PreferencesManager/XMLPrefs.class
> org/linfield/PreferencesManager/XMLPrefs.java
> org/linfield/PreferencesManager/PreferencesParser.java
>
> And the manifest in linfield.jar is:
>
> cat META-INF/MANIFEST.MF
> Manifest-Version: 1.0
> Created-By: 1.4.0 (Sun Microsystems Inc.)
>
> And most importantly, here is the main MANIFEST.MF file (for
> LibraryAlmaInterface.jar):
>
> cat META-INF/MANIFEST.MF
> Manifest-Version: 1.0
> Ant-Version: Apache Ant 1.8.3
> Created-By: 1.6.0_45-b06-451-11M4406 (Apple Inc.)
> Built-By: rtanner
> Main-Class: org.linfield.Library.PatronDataTransfer
> Class-Path: lib/jsch-0.1.49.jar lib/linfield.jar lib/log4j-1.2.15.jar
>  lib/xerces.jar
>
>
> I'm assuming that the problem is with the manifest, but I have no idea
> what it is.  Any help would be greatly appreciated.
>
> Thanks,
>
>
> Rob Tanner
> Linfield College
>
>
>
>
>


-- 
*Joe Attardi*
joe@attardi.net

Re: Access jar files in a library directory in the jar file

Posted by Vimil Saju <vi...@yahoo.com>.
The JVM won't look into nested jar files for classes.  Eclipse has a FatJar feature that lets you create runnable jars with nested jars within it.
for ant I think you can use one-jar. Here is a link http://one-jar.sourceforge.net/


________________________________
 From: Rob Tanner <ca...@gmail.com>
To: user@ant.apache.org 
Sent: Monday, June 17, 2013 3:38 PM
Subject: Access jar files in a library directory in the jar file
 

Hi,

I'm trying to build a runnable jar file that includes several libraries that are also jar files.  My problem is that Java does not seem to be able to find the libraries.  I get this message when I try to run the jar file:

java -jar LibraryAlmaInterface.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/linfield/PreferencesManager/XMLPrefs
        at org.linfield.Library.PatronDataTransfer.<clinit>(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.linfield.PreferencesManager.XMLPrefs
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 1 more

You can see from the table of contents that the c;ass file is there:

jar tf LibraryAlmaInterface.jar
META-INF/
META-INF/MANIFEST.MF
lib/
org/
org/linfield/
org/linfield/Library/
org/linfield/Library/Workers/
lib/jsch-0.1.49.jar
lib/linfield.jar
lib/log4j-1.2.15.jar
lib/xerces.jar
org/linfield/Library/CalculateBarcode.class
org/linfield/Library/PatronDataTransfer.class
org/linfield/Library/Workers/MyUserInfo.class
org/linfield/Library/Workers/PatronLoadsXML.class
org/linfield/Library/Workers/SecureFTPHandler.class

And the linfield.jar contains the class that the loader can't find:

META-INF/
META-INF/MANIFEST.MF
org/
org/linfield/
org/linfield/PreferencesManager/
org/linfield/PreferencesManager/PreferencesParser.class
org/linfield/PreferencesManager/XMLPrefs.class
org/linfield/PreferencesManager/XMLPrefs.java
org/linfield/PreferencesManager/PreferencesParser.java

And the manifest in linfield.jar is:

cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.4.0 (Sun Microsystems Inc.)

And most importantly, here is the main MANIFEST.MF file (for LibraryAlmaInterface.jar):

cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.3
Created-By: 1.6.0_45-b06-451-11M4406 (Apple Inc.)
Built-By: rtanner
Main-Class: org.linfield.Library.PatronDataTransfer
Class-Path: lib/jsch-0.1.49.jar lib/linfield.jar lib/log4j-1.2.15.jar 
lib/xerces.jar


I'm assuming that the problem is with the manifest, but I have no idea what it is.  Any help would be greatly appreciated.

Thanks,


Rob Tanner
Linfield College