aspose file tools*
The moose likes Java in General and the fly likes Running with jar files in jar file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running with jar files in jar file." Watch "Running with jar files in jar file." New topic
Author

Running with jar files in jar file.

William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

I want to make one jar file (A.jar) with my class file and the other jar files (B.jar & C.jar) I need to run. I am writing a test driver which uses the Jakarta Common Http Client, for which I need two jar files (B.jar & C.jar). My code runs fine if I have these Http Client jar files (B.jar & C.jar) somewhere and use set the classpath correctly.
But I would like to place these two jar files (B.jar & C.jar) into the jar file I am making (A.jar), so that installing all this will be simpler. I am using Ant and am able to create the jar file (A.jar) with the class file and Http Client jars (B.jar & C.jar). The problem comes when I try and run. I am creating the MANIFEST.MF file within my Ant jar task and setting my classpath there:

But when I run this I get:

Any ideas?
[ March 18, 2004: Message edited by: William Barnes ]
[ March 18, 2004: Message edited by: William Barnes ]

Please ignore post, I have no idea what I am talking about.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

A co-worker has just told me that you can't use jar files in a jar file. (This was the same guy who told me I could in the first place.)
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
java.net.MalformedURLException: unknown protocol: commons-httpclient.jar
That's because you have an ill-formed Class-Path in your manifest file. They aren't supposed to be colon-separated.
But yes, you cannot use jars-within-jars. The Class-Path entry will look in the same directory for those jars, not for those jars inside this one.
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
I do something similar in my project by extracting the other .jars during he Ant build then jarring everything up into one .jar. Here is the relevant section of my Ant build. In it, I extract 4 .jar files and bundle my classes wit htheir contents:

Hope that helps,
brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Great idea! Exactly what I was looking for. Someway of putting everything into one jar file. Thank you.
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
Yeah, just rejar those 3rd-party classes into your own jar. That couldn't possibly violate any license agreements
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Oh. I didn't know that would be an issue (sorry I don't know anything about license-es). If that is the case I will not do it. Thanks.
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Ok, so I go here: link and most of the legal stuff is talking about me changing the Jakarta code - which I am not doing. I am just using it.
Finding the legal stuff which I think is talking about me the following needs to be included:

Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Where exactly I am suppose to include this isn't clear to me. How about if I create a README and put that into the jar?
I don't see any legal language which said I couldn't use the class files outside of the jar. I guess I don't see how putting the class files into my jar is that much different than using their jar files. I am not trying to hide anything. If you look in the resulting jar it would have entries like this:

I am just trying to understand this. I don't want to do anything to break the license.
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
Depends on the license, but, in my case, it does NOT violate the licenses. Some licenses allow you to distribute/use the binary code in your own apps as long as you include their license with your app.
Your mileage may vary.
brian
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
William, it is all stated in section 4 of the license

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

You are allowed to modified and redistribute the code as long as you create a notice text file which specifies the modifications made and the orginal license agreement.
Regards
Nigel
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

Thanks, that helps.
I was confused with the terminalogy as I didn't think of expanding a jar file as modifing code. But I can see it as redistributing.
Geoffrey Falk
Ranch Hand

Joined: Aug 17, 2001
Posts: 171
    
    1
You could write your own classloader to load classes from a jar packaged inside another jar file. Not sure of the details of how to do that, though.
Geoffrey


Sun Certified Programmer for the Java 2 Platform
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

I would think that is isn't fairplay, to only put the notice in the jar, since nearly nobody will look inside jar files.
I would ship it in addition to this jar file and my own License-statement.


http://home.arcor.de/hirnstrom/bewerbung
 
jQuery in Action, 2nd edition
 
subject: Running with jar files in jar file.