• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

executable jar files that contain jar files

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They work fine, but I agree that it's not generally worth it.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and in case you're wondering what those tools actually are, check out "autojar" and "one-jar".
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic