How to copy one jar inside another

How to copy one jar inside another

Post by Mark Spac » Tue, 01 May 2007 04:35:28


Hi all. This is likely a repeat of an earlier question, but my Google
foo is weak and I can't find what I'm looking for.

I want to create a Java application that uses an external library (a
.jar that isn't in the default JRE), but I don't want to have to ask the
user to fiddle with adding other .jars to the class path, and I don't
want to take the time to set-up any kind of installer (Web start, etc.)

What's the best way of doing this?

I seem to remember someone mentioning a utility that would copy all
classes used in various .jars into file one file so that they could be
all used together, but I can't locate any. Any help/pointers much
appreciated.
 
 
 

How to copy one jar inside another

Post by Tor Iver W » Fri, 04 May 2007 04:21:55

P Sun, 29 Apr 2007 21:35:28 +0200, skrev Mark Space
< XXXX@XXXXX.COM >:


Ship the jar alongside your app jar and add a Class-Path entry to your app
jar's manifest (I assume you use Main-Class and the like to enable "java
-jar" invocation.

E.g.

Manifest-Version: 1.0
Main-Class: your.package.and.Class
Class-Path: other.jar

 
 
 

How to copy one jar inside another

Post by Mark Spac » Sun, 06 May 2007 03:48:32


Hmm, it's a thought, but I'm not sure exactly how this works. By "along
side" do you mean perhaps in a zip file, so the user will extract both
.jars to the same sub-directory? And will this always work? Is the
current running .jar always in the classpath? I'd prefer to not have to
ask the user to add, for example, $HOME/downloads to the classpath if it
normally isn't.

I might be asking for the impossible, but I'd like to understand how
this works.

Thanks for replying, btw!
 
 
 

How to copy one jar inside another

Post by a2490 » Sun, 06 May 2007 04:58:46


What about reading the documentation then?
 
 
 

How to copy one jar inside another

Post by Mark Spac » Sun, 06 May 2007 05:06:17


Isn't this the news group for asking for help? And if I read the
documentation and understood it, do you think I'd be posting here?
 
 
 

How to copy one jar inside another

Post by a2490 » Sun, 06 May 2007 06:06:34


This is not the newsgroup for people who want to be spoon feed and are
to lazy to do their own reading.
 
 
 

How to copy one jar inside another

Post by Mark Spac » Sun, 06 May 2007 06:53:16


To be more clear, my reading of the documentation says that what Tor
suggested will not work. The manifest file class-path still requires a
full path, and unless "other.jar" is in the root of the file system, it
won't be found. Thus it fails the general case. I know how to
manipulate a class path; I don't want a user to have to do so.

I find both of your replies to be quite rude. Feel free not not respond
to any further posts of mine. You're a waste of bandwidth.
 
 
 

How to copy one jar inside another

Post by Richard Re » Sun, 06 May 2007 20:31:06


I've used the class path extension with a relative dir:

Manifest-Version: 1.0
Main-Class: uk.ac.qub.trace.Main
Class-Path: tools.jar

all I had to do was put the tools.jar in the same dir as my executable jar
which meant the whole lot could just be unzipped to a dir

I take it you want the user to start the program by double clicking on the
jar? just thought that if that wasn't required you could use a start up
script that sets HOME as the current dir and adds all the jars in say,
HOME/lib to your classpath, think I remember reading somewhere that java 1.5
(or was it 1.6?) can add all the jars in a dir by just specifying the dir
rather than having to specify all the jars individually as well.
 
 
 

How to copy one jar inside another

Post by Lew » Sun, 06 May 2007 21:26:59


No, it doesn't.

--
Lew
 
 
 

How to copy one jar inside another

Post by Mark Spac » Mon, 07 May 2007 01:41:58


I have since found the relevant information, but the willingness of
certain people to be unhelpful and post snarky comments instead leaves
me completely nonplussed. Why even waste the 10 seconds of your life it
took to send those three words if it isn't going to be productive?
 
 
 

How to copy one jar inside another

Post by Mark Spac » Mon, 07 May 2007 01:46:51


Yes, that's basically what I'm after. There doesn't seem to be a way to
do it, automagically, which is unfortunate. I could write my own
classloader or take other rather extreme measures, but I was hoping to
avoid that. I'm sure there is a tool to do this already written, I just
can't recall the name, hence Google is unhelpful.

Still looking for helpful answers from helpful people...
 
 
 

How to copy one jar inside another

Post by Lew » Mon, 07 May 2007 01:58:03


I am sorry you found it unproductive. I am not clear why you call it "snarky"
or seem to have taken offensive. By providing the facts in that one instance,
i.e., that manifest CLASS-PATH entries need not be full (i.e., absolute)
paths, I was providing what I assessed to be helpful without wasting
unnecessary bandwidth on points that I did not choose to highlight.

Whether or not you find that information helpful is probably proportionate to
your desire to use relative pathnames in your manifest.

--
Lew
 
 
 

How to copy one jar inside another

Post by Lew » Mon, 07 May 2007 02:00:41


I am sorry you found it unproductive. I am not clear why you call it "snarky"
or seem to have taken offense. By providing the facts in that one instance,
i.e., that manifest CLASS-PATH entries need not be full (i.e., absolute)
paths, I was providing what I assessed to be helpful without wasting
unnecessary bandwidth on points that I did not choose to highlight.

Whether or not you find that information helpful is probably proportionate to
your desire to use relative pathnames in your manifest.

--
Lew
 
 
 

How to copy one jar inside another

Post by Lew » Mon, 07 May 2007 02:13:53


Double-clicking as you describe is implemented via the "java -jar" command
which ignores classpath entries and gets its classpath entirely from the jar.

--
Lew
 
 
 

How to copy one jar inside another

Post by Andrew Tho » Mon, 07 May 2007 02:21:24


..

* The answer is..


That requires a VM, and almost every modern VM comes
with web start as standard.


* Sun calls it web start. It allows the developer to add
resources to the classpath (including natives) and groups
of common jar's can be separated into 'extensions' that
can easily be used by any number of applications.

The end user experience** is straightforward and painless,
and the installer can create desktop shortcuts and menu
items at the user's request.

Here are some simple examples of web start
applications and web start API services..
< http://www.yqcomputer.com/ ;

** Once you are over the mild hurdle of determining if the
system is configured to understand JNLP launch files.
..

Communication is a two way street.

--
Andrew Thompson
http://www.yqcomputer.com/

Message posted via JavaKB.com
http://www.yqcomputer.com/