I am attempting to write an Ant task that wraps the org.apache.tools.ant.taskdefs.Java task. I am having a problem in determining how it is intended by the Ant API to execute tasks manually. For example, if I call org.apache.tools.ant.tasksdefs.Java.execute(), I receive a NullPointerException*. Is there a standard way to invoke existing tasks through the Ant API? Obviously the Ant framework does some setting up before calling execute(), hence the reason for the failure. Is there an Ant API such as TaskExecuter.execute(Task)? Assistance is most appreciated.
Please see the following test case which attempts to illustrate my objective in a trivial manner:
You need to set the project object (as you could see from the source code of Task.log).
You will also need to set the required attributes via the set*, and nested elements via the add*/create* methods.
Again, take a look at the source code - Ant is open source, after all.
A good book might also help - I'm using "Java Development with Ant" by Erik Hatcher et.al.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss: You need to set the project object (as you could see from the source code of Task.log).
I remember that when we set the project / target is also important ? I mean doing myJavaTask.setProject(getProject()),myJavaTask.setOwningTarget(getOwningTarget()) in the constructor probably wouldnt work since the Hello constructor does not get the Project and Target references by then?
Should they be set everytime we do a execute() or something / some other place?
may be you can verify.
Joined: Jul 11, 2001
Yes, you should do it everytime in execute().
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com