ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "todd runstein" <todd...@gmail.com>
Subject Re: How do I set a classpath for my custom task?
Date Wed, 21 Nov 2007 16:37:54 GMT
Ramu,

Thanks for the suggestions.  I've looked at both of these options, but
since this is a custom task that I'd like to include with an open
source project, neither of those options are ideal.  In the "taskdef",
I'd like the user of my task to only have to specify where my jar file
is.  However, because my task uses classes written by the user, I'd
like them to define that classpath in the task itself.

To be honest, I may not completely understand the entire problem yet.
Let me explain what I *think* the problem is, and hopefully someone
can tell me how to fix it.

Here is the taskdef that I would ask users to include in their build script:

<!-- classpathref needs to include migrate4j.jar so ant can find AntTask -->
<taskdef name="migrate" classname="com.eroi.migrate.migration.AntTask"
classpathref="lib.classpath" />

Then, here's the actual task in use:

<!-- The migrate task needs to know where user supplied classes are -->
<target name="run" depends="compile" >
        <migrate
        	version="1"
        	url="jdbc:h2:~/testH2"
        	driver="org.h2.Driver"
        	username="sa"
    		password=""
        	packagename="db.migrations"
                classpathref="user.classpath"
        />
</target>

Not to beat a dead horse, but the taskdef needs to find my code and my
code needs to find users code.  I think that the classpath in the
taskdef is being used to find my task (since the task loads properly),
but when code in my task runs, it is too late to change the classpath
so my code can't find the users classes.  I don't want the user to do
anything they wouldn't do with core ant tasks (except for the taskdef
entry).  I've started looking at the Java, Javac and JUnit tasks to
see how they do this, but it's not immediately clear how to replicate
their behavior.

I'm now looking at the Commandline object to see how that might work
with Execute.  If anyone has experience using these classes, I welcome
any help!  I may be about to run into a brick wall, so if I'm
obviously going down the wrong path, please let me know.

Todd


On Nov 20, 2007 8:43 PM, Ramu Sethu <sramhu@yahoo.co.in> wrote:
> HI todd
>
> Have you tried the following option ??
> 1. -lib option
> 2. classpath attribute in taskdef
>
>
>
> On Nov 21, 2007 2:15 AM, todd runstein <toddrun@gmail.com> wrote:
>
> > I'm writing an ant task that calls a Java class named Engine.  Engine
> > is in a jar file that is included in my taskdef using the classpath
> > tag.  This all works great.
> >
> > The problem I'm having is that one of Engine's methods calls
> > "Class.forName()", trying to dynamically add a class file that is not
> > in it's jar file.  Here I'm getting a ClassNotFoundException.  I've
> > tried a few things to manually set the classpath that Ant uses, but
> > I'm just hacking aimlessly and have had no luck.  Could someone give
> > me some direction to manually adding to the classpath that Engine will
> > ultimately work with?
> >
> > Thanks in advance!
> >
> > Todd
> >
> > --
> >
> >
> > ----------------------------------------------------------------------
> > The only "dumb question" is the one you were too afraid to ask.
> > ________________________________________
> > Check out RouteRuler - Free software for runners, cyclists, walkers, etc.
> > http://routeruler.sourceforge.net
> > ________________________________________
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >
>
>
> --
> Thank you
> Ramu S
>
>  If A is success in life, then A equals x plus y plus z. Work is x; y is
> play; and z is keeping your mouth shut.
> - Albert Einstein
>



-- 


----------------------------------------------------------------------
The only "dumb question" is the one you were too afraid to ask.
________________________________________
Check out RouteRuler - Free software for runners, cyclists, walkers, etc.
http://routeruler.sourceforge.net
________________________________________

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


Mime
View raw message