How to get the classpath from ant build file

Posted on 2008-06-13
Medium Priority
Last Modified: 2008-06-13
I have a ant build file as follows:
<project name="test" basedir=".">
      <property name="lib.dir"           value="/data/java_library/ext"/>
      <path id="project.classpath">
            <fileset dir="${lib.dir}">
                  <include name="**/*.jar"/>
                  <include name="**/*.zip"/>

I would to run something like:

MYCLASSPATH=`ant -q cp`

which should set the environment variable MYCLASSPATH to whatever is defined in the ant build file.

how can I do that?

Question by:dportabella
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 86

Accepted Solution

CEHJ earned 2000 total points
ID: 21780924
See below:
<property name="cp" refid="project.classpath" />
<echo message="${cp}" />

Open in new window


Author Comment

ID: 21781304
It works!
Thanks CEHJ.

If someone is interested, add this to the build.xml
      <property name="cp" refid="project.classpath" />
      <target name="cp" description="Shows the classpath">
            <echo message="${cp}"/>
And then execute:
MYCLASSPATH=`ant -q cp | sed -n -e "s/     \[echo\] //p"`

LVL 86

Expert Comment

ID: 21781434

You might find it more convenient to do
      <property name="cp" refid="project.classpath" />
        <echo message="${cp}" file="cp.txt" />

Open in new window


Author Comment

ID: 21781497

LVL 86

Expert Comment

ID: 21781588
And of course you could always print it from your app ;-)

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question