• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Ant classpth problem

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic