You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by John Guthrie <jg...@psynapsetech.net> on 2003/03/12 21:30:48 UTC

Classpath in Java task

i am writing a task that wraps a java routine. my (squonking good) copy of
'java development with ant' gives an example of this (p. 491). so in my task
i create a Java object in my execute() and try to use that

problem is that i set the classpath based on the task settings and, when i
run it, i get a NoClassDefException on a class that is in the rt.jar. if i
add the jre's rt.jar to the classpath it works (well, it fails in a
different place, and that's progress).

so my question is how do i get the rt.jar into my Java object's classpath?
is there a way to get the classpath that is in my task and pass that on to
the Java task (along with that the user specified), and/or is that even a
good idea?

thanks.

---
john


Re: Classpath in Java task

Posted by Mike McNally <m5...@works.com>.
> the classpathref basically points to a bunch of support jars the ultimate
> java class needs (e.g. antlr.jar) but not rt.jar (who ever needs to add
> rt.jar to their classpath?)

Well, as I understand it the crux of the matter is that your task is 
going to be loaded with the system classpath if it's on it, in which 
case it'll be able to get to rt.jar just fine.  But now you're going
to have problems getting to other stuff that's *not* on the system
classpath.

If you can get all of your tools into a jar file to support your task,
then you can impose the same sort of rules that other stuff imposes
for similar reasons: have users ensure that your .jar file is on the
system classpath (most simply, have it be copied into the ant lib).

In my case, I went the other way and set up my application build to
have the Java libraries on my internal build classpath.  But then
my tasks are quite specific to my application and uninteresting
outside of my own build, so having control of the build classpath
is not a problem for me.


--
[ you are my main foo ] Mike McNally -- m5@works.com

Re: Classpath in Java task

Posted by John Guthrie <jg...@psynapsetech.net>.
> > so my question is how do i get the rt.jar into my Java object's
> > classpath?
>
> You could add the JRE libraries to the classpath you pass in to
> <taskdef , but that doesn't get you completely out of the fire.
>

but i don't want to have to hunt up where the jre is, or require folks using
my task to do so either. i want to be able to pass on the classpath that the
task is using if i can really.

> > is there a way to get the classpath that is in my task and pass
> > that on to the Java task (along with that the user specified),
> > and/or is that even a good idea?
>
> How exactly is your <taskdef set up?
>

i am testing with something a la
 <target name="oofa">
    <taskdef name="loofa" classname="org.foo.Loofa"
classpathref="some.classpath">
   ....

the classpathref basically points to a bunch of support jars the ultimate
java class needs (e.g. antlr.jar) but not rt.jar (who ever needs to add
rt.jar to their classpath?)

thanks.

john


Re: Classpath in Java task

Posted by Mike McNally <m5...@works.com>.
> so my question is how do i get the rt.jar into my Java object's
> classpath?

You could add the JRE libraries to the classpath you pass in to
<taskdef , but that doesn't get you completely out of the fire.

> is there a way to get the classpath that is in my task and pass
> that on to the Java task (along with that the user specified),
> and/or is that even a good idea?

How exactly is your <taskdef set up?


--
[ you are my main foo ] Mike McNally -- m5@works.com