• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ant classpth problem

 
Hrishikesh Ghatnekar
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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

</description>

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


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

....

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" />

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



Now the abc8.0-7.jar , xyz8.0-227.jar contains a xml and a property file of same name , say ourprog.properties , 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 ourprog.properties.



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
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic