0

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:\Software\es_ws\AntDemo\build.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:\Software\es_ws\AntDemo\buildDirectory

What does this warning mean?

Thank you!

Volodymyr Levytskyi
  • 3,364
  • 9
  • 46
  • 83
  • You need to create an executable jar by including a "Class-Path" entry in your jar's manifest. For an example see: http://stackoverflow.com/questions/3143567/cannot-find-main-class-in-file-compiled-with-ant/3144290#3144290 – Mark O'Connor Jun 06 '14 at 19:28

2 Answers2

2

If you need that the content of jsoup.jar is included on your AntDemo.jar you can do it on several ways. My suggestion is use this solution:

<jar destfile="${dist.dir}/AntDemo.jar" >
    <manifest>
        <attribute name="Main-Class" value="ant.test" />
    </manifest>
    <fileset dir="${build.dir}" />
    <zipfileset includes="**/*.class" src="lib/jsoup-1.7.3.jar" />
</jar>
F.Rosado
  • 487
  • 4
  • 20
1

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.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724