You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ognjen Blagojevic <og...@etf.bg.ac.yu> on 2007/08/10 12:21:20 UTC
Java task, classpath problem
Hi,
Can someone try to explain this behavior of java ant task:
<target name="test1">
<java classname="com.sun.xml.internal.bind.v2.ContextFactory"/>
</target>
gives:
java.lang.NoSuchMethodException: (...)ContextFactory.main
Which is what I expected. ContextFactory is class in JRE's lib rt.jar,
java task can find it, but it does not have main method. However, this task:
<path id="emptyClasspath">
</path>
<target name="test2">
<java
classname="com.sun.xml.internal.bind.v2.ContextFactory"
classpathref="emptyClasspath"/>
</target>
gives
Could not find com.sun.xml.internal.bind.v2.ContextFactory.
Make sure you have it in your classpath
Now, I expect when I put classpathref attribute in java task, that JRE
lib is still in the classpath, but it seems that this is not the case.
(?) Ant cannot find ContextFactory anymore.
Is this a bug?
I use latest released Ant (1.7.0) and Java (1.6.0_02)
Regards,
Ognjen
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Java task, classpath problem
Posted by Ognjen Blagojevic <og...@etf.bg.ac.yu>.
Hi Peter,
Thanks for your answer. And sorry for late reply, I was on vacation.
Peter Reilly wrote:
> The <java> task does strange things with the classloader.
> My advice would be to use fork="yes" unless there
> is a reason not to.
Yes, I see. fork="yes" solved the problem.
> As regards the exception you are seeing, this is as far
> as I can see behaviour as designed.
Then it is strangely designed. See below.
> If one gives a classpath to the <java> task, the classname
> *must* be in the classpath, for example:
>
> <path id="empty"/>
> <java classname="java.lang.Object" classpathref="empty"/>
This returns "Could not find java.lang.Object.", and adding fork="yes"
returns (expected) "NoSuchMethodError".
In other words, using fork="yes" implies that rt.jar is in classpath,
otherwise (fork="no"), rt.jar is not in the classpath. Right?
Regards,
Ognjen
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Java task, classpath problem
Posted by Peter Reilly <pe...@gmail.com>.
The <java> task does strange things with the classloader.
My advice would be to use fork="yes" unless there
is a reason not to.
As regards the exception you are seeing, this is as far
as I can see behaviour as designed.
If one gives a classpath to the <java> task, the classname
*must* be in the classpath, for example:
<path id="empty"/>
<java classname="java.lang.Object" classpathref="empty"/>
-- Could not find java.lang.Object. Make sure you have it in your classpath.
However, there is a bug in ant with regard to the
com.sun.xml.internal.bind.v2.* classes.
There are in the rt.jar for java6, and these packages need to be
placed in the JavaEnvUtils.java class. I suspect that your original build file
ran into this bug.
This should be fixed soon, but in the meantime, you should
use fork="yes".
Peter
On 8/10/07, Ognjen Blagojevic <og...@etf.bg.ac.yu> wrote:
> Hi,
>
> Can someone try to explain this behavior of java ant task:
>
> <target name="test1">
> <java classname="com.sun.xml.internal.bind.v2.ContextFactory"/>
> </target>
>
> gives:
>
> java.lang.NoSuchMethodException: (...)ContextFactory.main
>
> Which is what I expected. ContextFactory is class in JRE's lib rt.jar,
> java task can find it, but it does not have main method. However, this task:
>
>
> <path id="emptyClasspath">
> </path>
>
> <target name="test2">
> <java
> classname="com.sun.xml.internal.bind.v2.ContextFactory"
> classpathref="emptyClasspath"/>
> </target>
>
> gives
>
> Could not find com.sun.xml.internal.bind.v2.ContextFactory.
> Make sure you have it in your classpath
>
> Now, I expect when I put classpathref attribute in java task, that JRE
> lib is still in the classpath, but it seems that this is not the case.
> (?) Ant cannot find ContextFactory anymore.
>
> Is this a bug?
>
> I use latest released Ant (1.7.0) and Java (1.6.0_02)
>
>
> Regards,
> Ognjen
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org