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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Ant classpth problem" Watch "Ant classpth problem" New topic
Author

Ant classpth problem

Hrishikesh Ghatnekar
Greenhorn

Joined: Oct 25, 2004
Posts: 28
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

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
Greenhorn

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant classpth problem
 
Similar Threads
Swing application don't run using apache-ANT
EJB deploy with WebSphere
Ant: earExport is not working with Jdk 1.4
java.lang.VerifyError:
CLASSPATH Help With ANT