Reputation: 71
say I am doing this:
java -jar someJar
"someJar" needs to reference tools.jar (for jsp compilation). I don't want to bundle tools.jar inside of someJar because I am afraid of a incompatibility with the executing JVM. I can't specify -classpath because it is ignored when -jar is used. I tried -Djava.ext.dirs and that did not work. Does anyone have an idea on how I can reference tools.jar from an executable jar?
Upvotes: 3
Views: 1570
Reputation: 1
I dont want the manifest to reference system dependent locations. I also cannot use -classpath when using -jar. I think the solution to this is using -classpath and not using -jar. Rather than putting the Main-Class in the manifest, I will put the main class on the command line.
Upvotes: 0
Reputation: 2261
The -jar option takes precedence over the -classpath option. You can however include a classpath reference in the manifest file of the jar that is being executed. There is an attribute called "Class-Path" which can contain relative or absolute references to other jars
Here's a snippet to show you how
<target name="jar" depends="compile">
<jar destfile="foo.jar" basedir="classes">
<manifest>
<attribute name="Main-Class" value="com.wiggle.foo" />
<attribute name="Class-Path"
value="C:/Java/jdk1.5.0_21/lib/tools.jar" />
</manifest>
</jar>
</target>
Note that if you want to include multiple jars in the Class-Path attribute that they have to be on a single line in the manifest file
Upvotes: 0
Reputation: 76719
Starting with Java 1.4, tools.jar needs to be included in the user classpath:
The tools classes are now in a separate archive (tools.jar) and can only be used if included in the user class path (to be explained shortly).
In other words, tools.jar cannot be placed in an extensions directory. This effectively means that specifying it in the manifest of the JAR might not be a good idea at all. There are a couple of options however:
java -cp $JDK_HOME/lib/tools.jar MainClass
command, where MainClass
is the fully qualified name of the class.Upvotes: 3