jar question

H

hilz

Hi all:

I am trying to create a library "myLib.jar" that includes three other jar
files:

myLibA.jar
myLibB.jar
myLibC.jar

I want myLib.jar to contain only myLibA.jar, myLibB.jar and myLibC.jar and a
manifest file
what do i need to include in the manifest file such that when an application
adds myLib.jar to its classpath, it will have access to the three included
libraries?

is that possible at all? if not, then what is the alternative?

thanks in advance for any answers or pointers.
hilz
 
W

Wendy S

hilz said:
what do i need to include in the manifest file such that when an application
adds myLib.jar to its classpath, it will have access to the three included
libraries?
is that possible at all? if not, then what is the alternative?

I don't think jar-within-jar will work, though I've never tried it. I would
(use Ant to) expand all three .jar files into the same directory structure
and then re-pack all the "loose" files into one .jar file.
 
A

Ann

hilz said:
Hi all:

I am trying to create a library "myLib.jar" that includes three other jar
files:

myLibA.jar
myLibB.jar
myLibC.jar

I want myLib.jar to contain only myLibA.jar, myLibB.jar and myLibC.jar and a
manifest file
what do i need to include in the manifest file such that when an application
adds myLib.jar to its classpath, it will have access to the three included
libraries?

is that possible at all? if not, then what is the alternative?

thanks in advance for any answers or pointers.
hilz

Why don't you want 4 manifest files?
 
K

KC Wong

hilz said:
I am trying to create a library "myLib.jar" that includes three other jar
files:

myLibA.jar
myLibB.jar
myLibC.jar

I want myLib.jar to contain only myLibA.jar, myLibB.jar and myLibC.jar and a
manifest file
what do i need to include in the manifest file such that when an application
adds myLib.jar to its classpath, it will have access to the three included
libraries?

is that possible at all? if not, then what is the alternative?

Impossible.

Extract myLibX.jar and re-jar them together as myLib.jar, or distribute them
separately.
 
D

Dave Glasser

Hi all:

I am trying to create a library "myLib.jar" that includes three other jar
files:

myLibA.jar
myLibB.jar
myLibC.jar

I want myLib.jar to contain only myLibA.jar, myLibB.jar and myLibC.jar and a
manifest file
what do i need to include in the manifest file such that when an application
adds myLib.jar to its classpath, it will have access to the three included
libraries?

is that possible at all?

No it's not, although a lot of people have wanted to do it.

It's theoretically possible to write a ClassLoader that would
accomplish this, but it probably wouldn't be practical. The reason is
that, in order to search for classes in, and extract them from, the
internal jar files, you'd have to first extract and decompress the
internal jars to memory or a temporary file anyway.
if not, then what is the alternative?

As someone mentioned, about the only practical way to accomplish this
is to merge the contents of all your jars into a single jar.


--
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.

http://qform.sourceforge.net

If you're a musician, check out RPitch Relative Pitch
Ear Training Software.

http://rpitch.sourceforge.net
 
H

hilz

Thanks to all.
i guess i will have to do just that - extract everything and re-jar
everything in one file.

many thanks for the quick responses.
hilz
 
F

FISH

hilz said:
Hi all:

I am trying to create a library "myLib.jar" that includes three other jar
files:

myLibA.jar
myLibB.jar
myLibC.jar


AFAIK this isn't going to work.

You may be interested to know, however, that the manifest supports a
Class-Path entry, which is a whitespace separated list of other
resources needed by your code. If, for example, you placed all the
support jars into a subdirectory called 'lib', then you would use
the following entry in your main application jar manifest:

Class-Path: lib/myLibA.jar lib/myLibB.jar lib/myLibC.jar

Which would allow your main jar file to be run via the -jar option
(assuming the same command line switches as Sun's JRE). To distribute
your work, supply a Zip or other suitable archive (NOT A JAR - unless
it's one of these clever self extracting jars!) with the 'executable'
jar file and the lib directory packed inside.


-FISH- ><>
 
O

Oscar kind

FISH said:
AFAIK this isn't going to work.

You may be interested to know, however, that the manifest supports a
Class-Path entry, which is a whitespace separated list of other
resources needed by your code. If, for example, you placed all the
support jars into a subdirectory called 'lib', then you would use
the following entry in your main application jar manifest:

Class-Path: lib/myLibA.jar lib/myLibB.jar lib/myLibC.jar

Also, the Class-Path header may appear more than once. So this would be
equivalent to FISH's suggestion:

Class-Path: lib/myLibA.jar
Class-Path: lib/myLibB.jar
Class-Path: lib/myLibC.jar
 
F

Ferenc Hechler

Hi Hilz,

there is an Eclipse Plug-In called Fat-Jar which builds
one fat jar from the source and all referenced jars (by
extracting all jars and repackaging), so you get one fat
jar which can be executed using "java -jar" without
any classpath troubles.

As an option you can use the "One-Jar" integration
which includes an extra class-loader which can handle
jars in a jar, then the referenced jars are not extracted,
but included as they are. So it is not impossible. ;)

Fat-Jar Eclipse Plug-In: http://fjep.sourceforge.net/
One-Jar: http://one-jar.sourceforge.net/

Best regards,
feri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top