ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antoine Lévy-Lambert <anto...@antbuild.com>
Subject Re: Why is Java task not adding my classpath ref unless fork="yes"?
Date Wed, 28 Jan 2004 18:19:56 GMT
Robert Paris wrote:

> I have the following in my build.xml:
>
> <path id="project.java.classpath">
>    <fileset dir="${dir.deploy}">
>        <include name="*.jar" />
>    </fileset>
> </path>
>
> <target name="run" depends="jar">
>    <java classname="com.mycompany.plaf.test.TestLAF">
>        <classpath refid="project.java.classpath" />
>    </java>
> </target>
>
> In the TestLAF class, I print out the java.class.path system property 
> and it doesn't include jars in the "deploy" folder. Can anyone tell me 
> what I'm doing wrong? The other weird thing is that the class 
> "com.mycompany.plaf.test.TestLAF" is in that same jar and when I use 
> "-debug" it prints that it loads that class from that jar file but it 
> still cannot find any other class in the jarfile and the 
> java.class.path does not include the jar file. I'm completely stumped!
>
Robert, first of all it is likely that ant does not manipulate the 
system variable java.class.path when setting a class path for a <java 
fork="false"/> invocation.
Secondly, a possible explanation why some classes of your jar are not 
found when fork="false" would be a problem with the ant class loader.
http://ant.apache.org/faq.html#delegating-classloader
the explanation would be :

com.mycompany.plaf.test.TestLAF is being found.
but it calls for instance a class/method of the Java runtime or 
something else which is in the class path when ant gets started.
this runtime method in turn calls back a specific class/method of your 
jar(s).
But the classloader of the runtime or of ant does not find the 
classloader containing your project jars.

One case where you have this type of behavior is if your jars contain 
for instance custom JDBC or JNDI drivers.
And if your class com.mycompany.test.TestLAF is invoking the factory 
methods of the runtime to instantiate a database/JNDI connection (for 
instance Context for JNDI),
then the factory methods of the runtime do not find your specific classes.

When you use fork="true" you do not use this ant class loader and things 
behave more predictably.

Cheers,
Antoine

> BTW, it does add the proper classpath ONLY if I use fork="yes".
>
> Thanks,
>
> Robert
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message