File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes executable jar files that contain jar files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "executable jar files that contain jar files" Watch "executable jar files that contain jar files" New topic
Author

executable jar files that contain jar files

Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
Is it now possible to have a truly self-contained jar file? That is, a jar file that contains jar files, the latter jar files being on the classpath? Back in the day, it wasn't. I am wondering if anything has changed. I see a few things in the ant task spec that are tantalizing but nothing definite.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

There's a bunch of products out there which attempt to do that. I haven't used them (because I don't see the need for such a thing) so I can't comment on how well they work.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

They work fine, but I agree that it's not generally worth it.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
...and in case you're wondering what those tools actually are, check out "autojar" and "one-jar".


Ping & DNS - updated with new look and Ping home screen widget
David Kilcy
Greenhorn

Joined: Aug 25, 2009
Posts: 20
I had a similar requirement. I just un-jar'ed all of the class files into one big directory then jar'ed that.

Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
Thanks all.

I need clarification from the boss. I had a zip file that could be extracted into a working program - lib directory, resources dir, etc. But the boss said he wanted to deploy a jar file. And I assume he meant an executable jar file, given he didn't care for my zip approach.

So this leaves me in a quandary about what he intended to do with all those jar files I need... perhaps they are there on the disk already... Or he expects a one-time copy of jar files. Blech.

Currently my ant task extracts the library jars into a tmp directory tree then includes that tree as a fileset in the jar task :-D

Takes forever to build that jar...
Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
I tried that David, it looks like the jar files have other files within them that conflict. I'm getting a peculiar error that translates as, "This is a time-wasting dead end."
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That may be indicative of an underlying issue, though, so it's good you found that out. If other libraries are including libraries already included in the app then they didn't properly shade their dependencies.
Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
I've not hit the same newb trap everyone else hits. I have my class files in a jar, and the libs in a separate directory, but I can't seem to run my main program because of classpath issues. That is, I can't seem to get the jars I need onto the classpath. It seems if you say "java -jar x.jar" then the -cp option is ignored.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

Tony Ennis wrote:That is, I can't seem to get the jars I need onto the classpath. It seems if you say "java -jar x.jar" then the -cp option is ignored.


When you use the "-jar" option, it will use the classpath that is specified in the manifest of that jar file.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

Tony Ennis wrote:I need clarification from the boss. I had a zip file that could be extracted into a working program - lib directory, resources dir, etc. But the boss said he wanted to deploy a jar file. And I assume he meant an executable jar file, given he didn't care for my zip approach.


Most of the time I see people asking about deploying a single jar file, it's people who don't really understand deployment. Or who have unrealistic requirements for it, let's say.

If you want the full top-of-the-line professional approach, then get yourself something which makes installers for the environment you're targeting, then distribute the installer. There are Java-specific installer-makers, I believe, but again I've never had a need to use such a thing.

If you want a quick-and-dirty approach, then just send out your jars with instructions to plunk them all into the same directory. If you're going to do an executable jar then make sure its manifest is set up to assume that's done. Otherwise send out a batch script which starts the main class and sets up the classpath accordingly.

The first approach would be targetting non-technical users. That way they get something they are used to and don't have to struggle with directories and so on. The second approach would be targetting users who know about directories and batch scripts and so on. These people don't need One Big Jar, they can deal with three or four jars or even a zip file. The first group probably couldn't even deal with One Big Jar. There might be a group in between those two who can deal with one jar but can't deal with more than one jar, but I doubt you'll find people like that very often.
Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
Indeed. I think we'd probably be ok with a zip file consisting of lib/... resources/... com/... etc. But I'm a contractor, and I have made my opinion known. Now I am following instructions.

Be that as it may, I have made reasonable changes to the manifest to specify a classpath relative to the deployment directory.

I am only slightly thwarted now. My resource directory doesn't seem to be on the classpath even though I added it to the manifest along with 50 jars. Does Class-Path in the manifest only work with jar files?
Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
the Classpath issue resolved by adding trailing "\" to the resource directory name.

This was an unpleasant generally unsatisfying day. I'm going home. So there.
Tony Ennis
Ranch Hand

Joined: May 22, 2003
Posts: 86
For anyone who follows in my frustrated footsteps, here is what you're looking for:



The fileset collects all the jars in my lib directory.
The Pathconvert smashes then into a space-sep string.
The Map within Pathconvert removes all my personal path information, making the remainder relative.

Later, in the zip task,



Jams the space-sep list of jars into the manifest. I couldn't find a way to wildcard it.

Season to taste, ymmv, yadda.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: executable jar files that contain jar files
 
Similar Threads
readme.txt
Bluetooth Apps using Nokia 6600
view content of file in a jar file
JFileChooser - To use or not to use
Attach file from JAR