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
Why couldn�t you just add file_a.jar and file_b.jar to the classpath like any other JARs?
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.
Joined: Feb 25, 2002
But file_a and file_b are inside the main jar file...how do i make a reference to them through the classpath?
Joined: Aug 08, 2006
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.
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.