The below target print_classpath in build xml demonstrates how to print the project classpath in ant script, this gives the ability to check loaded classpath at runtime.

<?xml version="1.0" encoding="UTF-8"?>
<project name="lms" default="print_classpath" basedir="D:/workspace/lms">
	<property environment="env" />
	<property name="catalina.home" value="D:/developer/apache-tomcat-6.0.32" />
	<property name="ant.dir" value="D:/developer/apache-ant-1.8.3" />
	<property name="webRoot.dir" value="${basedir}/webapp" />
	<property name="lib.dir" value="${webRoot.dir}/WEB-INF/lib" />

	<!-- init classpath -->
	<path id="project.classpath">
		<fileset dir="${lib.dir}">
			<include name="**/*.jar" />
		</fileset>
		<!-- add tomcat lib -->
		<fileset dir="${catalina.home}/lib">
			<include name="*.jar" />
		</fileset>

	</path>

	<!-- show classpath jars -->
	<target name="print_classpath">
		<property name="myclasspath" refid="project.classpath"/>
		<echo message="Classpath = ${myclasspath}"/>
	</target>

</project>

I executed the build.xml and got the following output, the all classes are printed in one line.

print_classpath:

[echo] Classpath = D:\workspace\lms\webapp\WEB-INF\lib\antlr-2.7.7.jar;D:\workspace\lms\webapp\WEB-INF\lib\aopalliance-1.0.jar;D:\workspace\lms\webapp\WEB-INF\lib\asm-3.3.1.jar; …

BUILD SUCCESSFUL

The below is the example to print the formatted the classpath:

	<!-- get the source compile classpath in a printable form -->

	<pathconvert pathsep="${line.separator}|   |-- "
             property="echo.path.compile"
             refid="project.classpath">
	</pathconvert>

	<!-- show classpath jars -->
	<target name="print_classpath">
		<echo message="|-- compile classpath"/>
		<echo message="|   |"/>
		<echo message="|   |-- ${echo.path.compile}"/>
	</target>

The output is as below, it is much better good-looking than previous one.

[echo] |– compile classpath
[echo] | |
[echo] | |– D:\workspace\lms\webapp\WEB-INF\lib\antlr-2.7.7.jar
[echo] | |– D:\workspace\lms\webapp\WEB-INF\lib\aopalliance-1.0.jar