ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xsli2 <>
Subject Help: create an executable JAR file including 3rd party JAR files
Date Wed, 21 Dec 2011 20:00:41 GMT
Dear All:

My directory structure is the following:
libs/externa/  containing a.jar, b.jar
libs/installed/  the generated runnable JAR file, "sample.jar", will be here

src/ containing Java source files
build/ containing Java class files
The main class is x.y.z.MyMain

I have had a really hard time to create a runnable JAR file using
Ant(version 1.6.5). The JAR file, libs/installed/sample.jar, can be
generated. However, when I run it, the classes inside a.jar or b.jar are not
available and causes NullPointerException. When I un-tar sample.jar,
everything is there. I think manifest classpath is causing the problem. 

Following is my brief build.xml:

	<filelist id="external.jars" dir="libs/external">
		<file name="a.jar" />
		<file name="b.jar" />
	<path id="project.classpath">
		<pathelement location="./build" />
		<filelist refid="external.jars"/>

	<target name="build" depends="init">
		<javac debug="true" debuglevel="${debuglevel}" destdir="${build.dir}"
source="${source}" target="${target}">
			<src path="src" />
			<classpath refid="project.classpath" />

	<target name="jar" depends="clean, build">
		<pathconvert property="manifest.classpath" pathsep=" ">
					<flattenmapper />

					<globmapper from="*" to="libs/external/*" />
				<filelist refid="external.jars"/>

		<jar destfile="libs/installed/sample.jar" basedir="./build" update="true">
				<attribute name="Main-Class" value="x.y.z.MyMain" />
				<attribute name="Class-Path" value="${manifest.classpath}"/>
			<fileset dir="${externals.dir}"/>

Thank you very much.

View this message in context:
Sent from the Ant - Users mailing list archive at

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

View raw message