Define Classpath Ant build

Define Classpath Ant build

If you are working on ant based jav project and using build.xml to create jar, war or ear file. First thing you have to do is compile all files. To set classpath in build.xml file and take reference of it please have sample below:

<?xml version="1.0" encoding="UTF-8"?>
<project name="Java Honk set classpath sample" default="all" basedir=".">

	<property name="classdir" value="${basedir}/build/classes" />
	
	<!-- Define the CLASSPATH -->
	<path id="classpath">
		<fileset dir="${basedir}/lib">
			<include name="*.jar" />
		</fileset>
	</path>
	
	<!-- Main target -->
	<target name="all" depends="compile" />	

	<!-- Compile target -->
	<target name="compile">
		<javac srcdir="src" destdir="build/classes" includeantruntime="false">
			<classpath refid="classpath" />
		</javac>
	</target>

</project>
  • For more information on set classpath in ant please refer this link 

Leave a Reply

Your email address will not be published. Required fields are marked *