How to add .jar to build.xml?

I have a Java program that implements .jar and cannot compile without it. I downloaded all the files with the corresponding directory names, but I donโ€™t know how to make build.xml know where to find the .jar. The jar file is in my src / program directory. I know that I need to use the <classpath> . Do I need to put it in my "compile" target inside the <javac> ?

+4
source share
2 answers
 <?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> 
+2
source

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

Example directly from ant.

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

Source: https://habr.com/ru/post/1398736/


All Articles