aspose file tools
The moose likes Java in General and the fly likes Ant classpth problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Ant classpth problem" Watch "Ant classpth problem" New topic

Ant classpth problem

Hrishikesh Ghatnekar

Joined: Oct 25, 2004
Posts: 28

Currently we are facing a very strange problem related to class path.

We have a program which we normally run by using ant.

To cut long story short , our program runs when we set the classpath using command prompt , and doesn't run when we try to run it through the ant ( which contains the same class path )

Here are the details

Non Working situation..

Our ant file contains following entire


<import file="prog.xml"/>
<!-- Import the prog properties -->
<property file="${prog.installLocation}/bin/"/>

<target name="startPROG" description="Start the PROG">


And prog. xml contains following entries

<!-- Define the location of the prog -->
<property name="prog.installLocation" value="F:\ourprog\try"/>

<!-- ClassPath -->
<path id="task.classpath">
<pathelement location="${prog.installLocation}/lib/abc8.0-7.jar" />
<pathelement location="${prog.installLocation}/lib/abc8.0-3.jar" />
<pathelement location="${prog.installLocation}/lib/xyz8.0-227.jar" />

<echo>prog.installLocation is = "${prog.installLocation}"</echo>
<property name="cp" refid="task.classpath"/>
<echo message="Classpath is ${cp}"/>
<taskdef name="startPROG"
classpathref="task.classpath" />

Now the abc8.0-7.jar , xyz8.0-227.jar contains a xml and a property file of same name , say , ourprogram.xml. Though the name are same the contains are different.

When we try to run our program like , ant startPROG

We get message can not find

Now working solution

Open a command prompt

set classpath=F:\ourprog\try\abc8.0-7.jar;F:\ourprog\try\abc8.0-3.jar;F:\ourprog\try\xyz8.0-227.jar;

and then run the same command , ant startPROG
and the program WORKS.

Any idea what is going wrong here , and how can I debug further?
Santhosh Kumar
Ranch Hand

Joined: Nov 07, 2000
Posts: 242
Classpath you set while defining the taskdef is not visible inside the taskdef'd class due to hierarchy of classloaders the Ant use.

You can follow the approach mentioned in this post.
Hrishikesh Ghatnekar

Joined: Oct 25, 2004
Posts: 28
Gone through the post but answer is still not clear to me.

The following code will go in the java file and not is ant /xml file

AntClassLoader classLoader =
(AntClassLoader) getClass().getClassLoader();
String taskPath = classLoader.getClasspath();

Can you please tell me what are the changes needed in the xml file?
subject: Ant classpth problem