VOOZH about

URL: https://www.javacodegeeks.com/2015/03/displaying-paths-in-ant.html

⇱ Displaying Paths in Ant - Java Code Geeks


In the blog posts Java and Ant Properties Refresher and Ant <echoproperties /> Task, I wrote about how being able to see how properties are seen by an Ant build can be helpful in understanding that build better. It is often the case that it’d also be valuable to see various paths used in the build as the build sees them, especially if the paths are composed of other paths and pieces from other build files. Fortunately, as described in the StackOverflow thread Ant: how to echo class path variable to a file, this is easily done with Ant’s PathConvert task.

The following XML snippet is a very simple Ant build file that demonstrates use of <pathconvert> to display an Ant path’s contents via the normal mechanisms used to display Ant properties.

build-show-paths.xml: Ant build.xml Using pathconvert

<project name="ShowPaths" default="showPaths" basedir=".">

 <path id="classpath">
 <pathelement path="C:\groovy-2.4.0\lib"/>
 <pathelement location="C:\lib\tika-1.7\tika-app-1.7.jar"/>
 </path>
 
 <target name="showPaths">
 <pathconvert property="classpath.path" refid="classpath" />
 <echo message="classpath = ${classpath.path}" />
 </target>

</project>

The simple Ant build file example shown above creates an Ant path named “classpath”. It then uses the pathconvert task to create a new property (“classpath.path”) that holds the value held in the “classpath” path. With this done, the property “classpath.path” can have its value displayed using Ant’s echo task as demonstrated in “Java and Ant Properties Refresher.”

👁 antShowPathsExamples_pathconvert

When debugging issues with Ant builds, use of Ant’s -verbose is often handy. However, sometimes -verbose is a heavier solution than is actually required and often the simple ability to easily identify what properties and paths the Ant build “sees” can be very helpful in diagnosing build issues.

Reference: Displaying Paths in Ant from our JCG partner Dustin Marx at the Inspired by Actual Events blog.
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Thank you!

We will contact you soon.

👁 Photo of Dustin Marx
Dustin Marx
March 23rd, 2015Last Updated: March 22nd, 2015
0 492 1 minute read
Subscribe

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Back to top button
Close
wpDiscuz