Using Echo in Ant to see the classpath

In trying to run unit tests (using JUnit) from Ant some tests were failing due to what appeared to be classpath issues.  I needed to see what all my classpath property contained.  I discovered the pathconvert Ant task.

Here is how I used it in my build file:

<!-- junit.classpath is what I want to see -->
<path id="junit.classpath">
  <fileset dir="lib">
    <include name="**/*.jar"/>
  </fileset>
  <path refid="test.mockinputfiles"/>
  <pathelement path="${dir.binaries}" />
</path>

<!-- Use pathconvert to put the output in to the echo.classpath property -->
<pathconvert pathsep="${line.separator}| |-- "
  property="echo.classpath"
  refid="junit.classpath">
</pathconvert>

<echo message="|-- JUnit Classpath"/>
<echo message="| |"/>
<echo message="| |-- ${echo.classpath}"/>

<junit fork="on" forkmode="once" haltonfailure="false" showoutput="on" printsummary="on" failureproperty="tests.failed">
  <classpath>
    <path refid="junit.classpath"/>
  </classpath>
  <!-- Other junit properties -->
</junit>
Advertisements

About stevewall123

I am a Lead Software Engineer in Minneapolis working for Thomson Reuters. I am currently working on projects using Java, JavaScript, Spring, Drools, Hazelcast, Liquibase and Tomcat. Previously, I used C#, GWT, Grails, Groovy, JMS and JBoss Drools Guvnor. In the past I have worked on projects using J2EE, Swing, Webwork, Hibernate, Spring, Spring-WS, JMS, JUnit and Ant.
This entry was posted in Ant and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s