ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Matèrne (jhm) <>
Subject AW: AW: Javac Run By Ant Script is Unable to Find External Jars
Date Mon, 25 Feb 2019 13:07:59 GMT
Could you post the content of the manifest file and your directory structure?

I suppose that the paths are not correct …




Von: Dennis Putnam [] 
Gesendet: Montag, 25. Februar 2019 13:09
Betreff: Re: AW: Javac Run By Ant Script is Unable to Find External Jars


My apologies again but I have not made any progress on this problem. Is there perhaps a better
forum I should be using at this point? I did make one discovery. It appears that although
the application works in Eclipse when I try to export it to a runnable jar using the Eclipse
wizard, the resulting jar fails as well. It seems to me that the problem is not ant specific
but something in the app build per se.

On 2/21/2019 10:18 AM, Dennis Putnam wrote:

I found an article on adding Maven dependencies to my ant script. While I'm getting a successful
build but the same exception when I run the jar, I hope this is getting me closer. At least
the pom.xml is in the build. I am wondering if the added fileset is right and working. Here
is my latest:

<?xml version="1.0" encoding="UTF-8"?>
<project name="KCBSEvents" default="jar" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
        <property name="" value=""/>
        <property name="resources" value="resource" />
        <property name="jardir" value="KCBSEvents" />
        <property name="KCBSDir" value="src/KCBSEvents" />
        <property name="member.number" value="000000" />
        <property name="" value="" />
        <property name="jarpath" value="/${user.home}/.m2/repository" />
        <path id="maven-ant-tasks.classpath" path="/lib/jvm-exports/maven-ant-tasks-2.1.3.jar"
        <typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath" />
        <artifact:pom id="pomfile" file="pom.xml" />
        <artifact:dependencies filesetId="mvn-dependencies" pomRefId="pomfile" />
        <path id="compile-jars">
                <multirootfileset basedirs="${jarpath}/commons-io/2.5,${jarpath}/httpcomponents-client,${jarpath}/commons-logging/1.2,${jarpath}/commons-codec/1.10,/lib/java-ext/json-simple-1.1.1">
                        <include name="commons-io-2.5.jar" />
                        <include name="httpclient-4.5.6.jar" />
                        <include name="httpcore-4.4.10.jar" />
                        <include name="commons-logging-1.2.jar" />
                        <include name="commons-codec-1.10.jar" />
                        <include name="json-simple-1.1.1.jar" />
                <fileset refid="mvn-dependencies" />
        <target name="checkOS">
                <condition property="isWindows">
                        <os family="windows" />
                <condition property="isLinux">
                        <os family="unix" />
        <target name="if_windows" depends="checkOS" if="isWindows">
                <property name="jarfile" value="C:\temp\KCBSEvents.jar" />
                <property name="antcontrib" value="H:\html\Applets\ant-contrib" />
        <target name="if_linux" depends="checkOS" if="isLinux">
                <property name="jarfile" value="/tmp/${member.number}/KCBSEvents.jar" />
                <property name="antcontrib" value="/var/www/html/Applets/ant-contrib/ant-contrib-1.0b3.jar"
        <target name="setclass" depends="if_linux,if_windows">
                <taskdef resource="net/sf/antcontrib/">
                                <pathelement location="${antcontrib}" />
        <target name="incserial" depends="setclass">
                <copy todir="bin/${jardir}/${resources}">
                        <fileset dir="${KCBSDir}/${resources}">
                                <include name="${}" />
                                <expandproperties />
                <if> <isset Property="build.number" /> <then>
                        <echo message="update build requested" />
                </then> <else>
                        <echo message="new build requested" />
                        <buildnumber />
                </else> </if>
                <propertyfile file="bin/${jardir}/${resources}/${}">
                        <entry key="serialnumber" value="${build.number}" />
                        <entry key="membernumber" value="${member.number}" />
                        <entry key="name" value="${}" />
                <echo message="serial number: ${build.number}" />
        <target name="jar" description="Compile serialized jar" depends="incserial,if_windows,if_linux">
                <echo message="Using destination file ${jarfile}" />
                <javac srcdir="src" destdir="bin" includeantruntime="false" classpathref="compile-jars"
                <jar destfile="${jarfile}" basedir="bin" filesetmanifest="mergewithoutmain">
                                <attribute name="Manifest-Version" value="1.0"/>
                                <attribute name="Created-By" value="ant 1.9.2 on CentOS
7" />
                                <attribute name="Main-Class" value="KCBSEvents.KCBSEvents"

On 2/20/2019 3:22 PM, Jan Matèrne (jhm) wrote: 

If you have created your JAR the first step is done.
Starting the JAR could be done in several ways. Common is that you have to have all external
classes on the runtime classpath:
1. Hard coded start script.
Write a bash/bat-Script with the java command with all cp settings, e.g. (bat)
@echo off
java -cp /build/myjar.jar;lib/one.jar;lib/two.jar;lib/three.jar org.acme.Main %*
2. Wrapper script which collects all JARs in a dynamic way (see ant.bat|
3. Use Ant + <java><classpath> for starting
4. Create a runnable JAR which references the external JARs (manifest: main-class + classpath)
5. Create a shaded jar (uber jar, fat jar): include all classes from external jars into your
6. Use a launcher which uses a dependency manager for getting the classpath
You don't have to replicate path definitions in your buildfile, you could (and should) use
<javac><classpath id="runtime.cp"><fileset dir="lib" includes="**/*.jar"/>…
<java><classpath refid="runtime.cp"/>
You mave have a look at



  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message