Skip to main content



      Home
Home » Newcomers » Newcomers » Declaring Ant tasks for Task classes provided by official plugins
Declaring Ant tasks for Task classes provided by official plugins [message #252621] Fri, 28 March 2008 10:38 Go to next message
Eclipse UserFriend
I want to use the Apache FOP anttask in an ant script (from the DITA Open
Toolkit) that is started from inside my own Eclipse plugin via AntRunner.

If possible, I would like to use the official Eclipse FOP plugin. However,
while the provided jar contains the task class
(org.apache.fop.tools.anttasks.Fop, derived from
org.apache.tools.ant.Task), the plugin doesn't seem to declare any antTask
extension. Is that correct?


If I define the antTask in my own plugin's ant script with

<taskdef name="fop" classname="org.apache.fop.tools.anttasks.Fop"/>

I get the following error:


taskdef A class needed by class org.apache.fop.tools.anttasks.Fop cannot
be found: org.apache.tools.ant.Task


The very same script runs fine when started from the command line. Since
the class gets called from an ant script, and other Task instances are
created without problems when running in Eclipse, I assume that
org.apache.tools.ant.Task is in fact available, but that perhaps
org.apache.fop.tools.anttasks.Fop was laded by the plugin classloader,
while org.apache.tools.ant.Task was loaded by the ant classloader, making
them incompatible?


However, even if I remove dependencies to the org.apache.fop plugin from
my own plugin's manifest, put the fop.jar in a lib folder inside my
plugin, and declare the task with

<antTask name="fop" class="org.apache.fop.tools.anttasks.Fop"
library="lib/fop.jar"/>

I still get the same error message, even though the class should now only
be available to the Ant classloader.


Is there any sample project where a custom antTask is declared for an
existing subclass of org.apache.tools.ant.Task provided by an existing
plugin?


Side note: I am using some custom Task classes in my plugin as well. After
encountering some ClassCastExceptions and missing project configuration, I
figured that my classes were loaded by the plugin classloader instead of
the ant classloader. After I put them in a jar outside of the plugin build
path, everything went fine. However, this doesn't seem to work for the Fop
Task.


Thanks in advance for any insights!
Re: Declaring Ant tasks for Task classes provided by official plugins [message #252632 is a reply to message #252621] Fri, 28 March 2008 12:32 Go to previous message
Eclipse UserFriend
I found a workaround for the problem: I copied the source code of
org.apache.fop.tools.anttasks.Fop and put a clone called "MyFop" into the
jar file in the plugin's lib directory, declaring the "fop" antTask in the
plugin.xml with a reference to the MyFop class in the jar.

This led to an IllegalAccessError when MyFop tried to instantiate
org.apache.fop.tools.anttasks.FOPTaskStarter. After renaming this class to
"MyFOPTaskStarter", and thus avoiding confusion with the FOP plugin's
class, the PDF generation worked out just fine with the remaining classes
from the FOP plugin.


However, my original question still remains: can you declare Ant tasks for
Task classes provided by official plugins, when these plugins don't define
any antTask extensions? Because what I did here was creating my own Task
class again.
Previous Topic:NoClassDefFoundError from plugin
Next Topic:Java Template Management
Goto Forum:
  


Current Time: Thu May 08 02:23:41 EDT 2025

Powered by FUDForum. Page generated in 0.07786 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top