Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Including a jar within a jar

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to package a class file with 2 jar files that are in my classpath.

CLASSPATH=c:\java\include\ar.jar
Working directory (source/class file) : c:\eclipse\workspace\MyProject

Within my working directory, I am able to compile and run Test.java, creating Test.class. Both files are in my working directory.

Using Ant, I want a single jar that will include 'ar.jar' and 'Test.class' to be run on another environment. I would like to leave 'ar.jar' in the directory that it is currently in.

Here is my build.xml





The problem is that when I run 'java -jar MyJarFile.jar', I get a NoClassDefFoundError since it is not finding 'ar.jar'. The 'ar.jar' file is packaged in MyJarFile.jar, but I cannot figure out the correct Class-Path to reference 'ar.jar'.

Any advice?
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't do what you're trying to do. You could uncompress the jars you want to include and then re-jar them into the one jar (bad idea by the way: what happens when a new version of those jars becomes available?).

Another option is to simply ship your dependent jars in a subdirectory of your application (eg lib/) and then point your application (easiest would be to set the class-path in your Manifest file). That's what I'd do.

Edward
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should specify each jar files you used in the manifest file. For example, if you have 2 jar files a, b, you should have

Class-Path: a.jar b.jar

entry in the manifest file. Take note that they are separated by space.

Try replacing your class path entries in your script with this:

<attribute name="Class-Path" value= "java/include/.jar">
 
jerry conosm
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oooops! what I mean from above is

<attribute name="Class-Path" value= "java/include/ar.jar">
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are trying to do isn't supported by standard java, as far as I know. You can use http://one-jar.sourceforge.net/ to do so, though.
 
You've gotta fight it! Don't give in! Read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic