user1205853
user1205853

Reputation: 661

How to add a .jar in build.xml?

I have a java web program that implements a .jar and cannot compile without it. I have uploaded all of the files with appropriate directory names, but I do not know how to get the build.xml to know where to find the .jar. The jar file is in my src/program directory. I know I need to use the <classpath> tag. Do I need to put it in my "compile" target inside of the <javac> tag?

Upvotes: 4

Views: 8092

Answers (2)

Nurlan
Nurlan

Reputation: 673

<?xml version="1.0" encoding="utf-8"?>
<project name="helloworld" default="compile" basedir=".">
    <property name="project.src.dir" value="${basedir}/src"/>
    <property name="project.lib.dir" value="${basedir}/src/program"/>
    <property name="project.classes.dir" value="${basedir}/classes"/>

    <path id="lib.path">
        <fileset dir="${project.lib.dir}" includes="**/*.jar"/>
    </path>

    <target name="compile">
        <javac srcdir="${project.src.dir}" includes="**/*.java" destdir="${project.classes.dir}" classpathref="lib.path"/>
    </target>
</project>

Upvotes: 2

Dev
Dev

Reputation: 12196

You need to add the jar to the classpath attribute or <classpath> tag of your <javac> tag.

Example straight from the ant user guide.

<javac srcdir="${src}"
         destdir="${build}"
         classpath="xyz.jar"
         debug="on"
         source="1.4"
/>

Upvotes: 1

Related Questions