ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Duffey, Kevin" <>
Subject Problem running executable jar - classpath issues
Date Wed, 23 Jul 2003 22:35:56 GMT
Hi all,

My project builds everything into an executable .jar file, except it doesn't embed 3rd party
.jar files it relies on because the JVM doesn't support finding classes in .jar files embedded
in the main executing jar file. So, I zip everything up, when unzipped it creates a dir with
the executable .jar file in the root, and a lib directory where it places all 3rd party libraries.

My script is able to compile against it no problem:

	<path id="compile.classpath">
		<fileset dir="${lib.dir}">
			<include name="*.jar"/>

	<path id="test.classpath">
		<path refid="compile.classpath"/>
		<pathelement location="${junit.jar}"/>
		<pathelement location="${test.dir}"/>

	<path id="run.classpath">
		<path refid="compile.classpath"/>
		<pathelement location="${build.dir}/classes"/>

The execute task:

	<target name="execute">
		<java jar="${dist.dir}/app.jar" fork="true" failonerror="false">
			<classpath refid="run.classpath"/>

The problem is, I build the app.jar into my <project root>/dist/app.jar, and the lib
files are not being found when it executes. They are in <project root>/lib/*.jar (also
known as ${lib.dir}). If I copy the lib directory to my dist directory, it works. Internally,
my code uses relative paths to find property files in the app.jar. But in my main class I
use Log4J, which is specified in the manifest class-path as lib/log4j.jar. Thus, it is relative
to the location of the startup of app.jar. However, it appears even though I have followed
the Java Development with Ant book, it still can't find my lib/*.jar files.

So, I am guessing that even though my build script is in <project root> and it starts
the app.jar from within <project root>/dist/app.jar, it is seeing the root dir as the
<project root>/dist/ directory. If it wasn't, then the relative paths in Class-Path
in the manifest file would work. And that would explain why when I copy it to the dist dir,
it works.

Can somebody please explain how to make this work? I don't want to have to copy my app.jar
into the <project root> dir, nor do I want to keep two directories of the libraries!
I want to use my <project root>/lib/*.jar from the app.jar located in <project root>/dist/app.jar,
and execute this from the build script.


Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
Version: 6.0.501 / Virus Database: 299 - Release Date: 7/14/2003

"The information contained in this e-mail message  may be confidential and 
protected from disclosure.  If you are not the intended recipient, any 
dissemination, distribution or copying is strictly prohibited.  If you think 
that you have received this e-mail message in error, please e-mail the 
sender at"

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message