Skip to content
Advertisement

How to set classpath in ant correctly?

I have my single dependency on path projectRoot/lib/jsoup.jar.

My build.xml is simple:

<project name="Ant-Demo" default="main" basedir=".">

    <property name="src.dir" value="src" />
    <property name="build.dir" value="buildDirectory" />
    <property name="dist.dir" value="dist" />
    <property name="docs.dir" value="docs" />
    <property name="lib.dir" value="lib" />

    <path id="build.classpath">
        <pathelement location="lib/jsoup-1.7.3.jar"/>
    </path>

    <target name="compile" depends="clean,makedir">
        <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath" />
    </target>

    <target name="jar" depends="compile">
    <jar destfile="${dist.dir}/AntDemo,jar" basedir="${build.dir}">
        <manifest>
            <attribute name="Main-Class" value="ant.test" />
        </manifest>
    </jar>
</target>
    ........................................... 

This doesn’t work, because jsoup.jar is not included in final AntDemo.jar.

EDIT When compile target is running the output has warning:

compile:
    [javac] D:Softwarees_wsAntDemobuild.xml:30: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
    [javac] Compiling 2 source files to D:Softwarees_wsAntDemobuildDirectory

What does this warning mean?

Thank you!

Advertisement

Answer

When you compile classes and specify a classpath, the classes and other resources in that javac classpath don’t get copied over to the destination, in ant or in typical command line javac. You need to copy them over manually, or in ant with a copy or other means.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement