• 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

Classpath and Jar file

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a Jar file with some class files - file1.jar . These class files need 2 more jar files(file_a.jar and file_b.jar)in the classpath to run correctly.
I want to bundle the dependent jar files inside the main jar file.

Is there any way to make the dependent jar files a part of the classpath without un jarring them.

|-- class files
file1.jar----------|
|-- file_a.jar, file_2.jar

i am looking at someting line

java -cp file_a.jar;file_b.jar -jar file1.jar

The only other option i am seeing is to un jarr this file and put file_a.jar and file_b.jar in the system classpath

Regards
Badari
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why couldn�t you just add file_a.jar and file_b.jar to the classpath like any other JARs?

Your command

java -cp file_a.jar;file_b.jar -jar file1.jar

should work just fine. It puts the two JARs on the class path. You shouldn�t have to unjar them. They could go on the system class path, or on the class path of the Java command you use to launch file1.jar.
 
badari gururaj
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But file_a and file_b are inside the main jar file...how do i make a reference to them through the classpath?
 
John Kelty
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could write a custom class loader that will know to look inside the outer jar.

Otherwise, you are stuck with needing to extract the inner JARs out of the main one.

http://forums.java.net/jive/thread.jspa?threadID=342&messageID=9588

has some information on using ant to automate that task.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the manifest of the first jar, define a property like this:

Class-Path: file1.jar file2.jar file3.jar

This way all this jars will be automatically included in the first jar as dependencies.

See the Java Deployment Tutorial for more information on this topic and other manifest properties.
[ October 18, 2006: Message edited by: Edwin Dalorzo ]
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This way all this jars will be automatically included in the first jar as dependencies.

Jars listed in the MANIFEST.MF file are relative to the location of the jar containing the MAINFEST.MF file.

From the link you provided:


Note : The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.

 
reply
    Bookmark Topic Watch Topic
  • New Topic