You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Magali & Edouard sur Free <ma...@free.fr> on 2005/01/04 21:40:15 UTC
Typdef/taskdef behaviour and introspection
Hi to all;
Having faced a problem too long without precise answer. My problem is the
following.
I have developed an Ant task that performs XSLT inside. So far, so good,
provided I put my XSLT implementation in Ant 'lib' directory, the task works
fine.
But as soon as I try to refer to this task via the 'typedef' task with a
provided classpath that contains both my task jar and the XSLT
implementation jar (having remove any implementation from Ant 'lib'
directory at the same time) - this implementation is either saxon-6.2.2.jar
or xalan-2.4.1.jar - the implementation task cannot load.
With Xalan, I get this
javax.xml.transform.TransformerFactoryConfigurationError : Provider
org.apache.xalan.processor.TransformerFactoryImpl not found
problem, which demonstrates that the JRE cannot find such an implementation,
though it is present in my 'typedef' declaration (for sure).
As I understand, the Java XSLT API performs introspection by creating an
instance of the 'javax.xml.transform.TransformerFactory' abstract class, and
by looking at the Java system 'javax.xml.transform.TransformerFactory'
property.
My question is: how to make all this work?
A piece of answer would be: how to force the underlying class loader of the
Ant 'typedef' task to load the whole content of a jar (even those that may
be used by introspection), instead of just loading the classes declared and
discovered at compile time?
I really need to separate my XSLT implementation and my task from Ant 'lib'
directory!
Thank you very much for your attention, and I hope that a Java class loader
can indicate how to solve that.
Cheers and happy all,
Edouard
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.809 / Virus Database: 551 - Release Date: 09/12/2004
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Typdef/taskdef behaviour and introspection
Posted by Yves Martin <yv...@elca.ch>.
"Magali & Edouard sur Free" <ma...@free.fr> writes:
> As I understand, the Java XSLT API performs introspection by creating an
> instance of the 'javax.xml.transform.TransformerFactory' abstract class, and
> by looking at the Java system 'javax.xml.transform.TransformerFactory'
> property.
>
> My question is: how to make all this work?
>
> A piece of answer would be: how to force the underlying class loader of the
> Ant 'typedef' task to load the whole content of a jar (even those that may
> be used by introspection), instead of just loading the classes declared and
> discovered at compile time?
>
> I really need to separate my XSLT implementation and my task from Ant 'lib'
> directory!
The problem is not that the whole content of the jar is loaded (it is !) - but
that classes present in JRE rt.jar are not able to find the resource
META-INF/services/javax.xml.transform.TransformerFactory in its only visible
ClassLoader: the system ClassLoader.
You may want to read javax.xml.transform.TransformerFactory.newInstance() to
know more about the factory loading.
The only work-around I see is to short-circuit the API when you call the
TransformerFactory in your Ant task with the following code:
. is = YourTask.class.getClassLoader()
.getResourceAsStream("META-INF/services/javax.xml.transform.TransformerFactory")
. Read the Class name from the InputStream
. Load the corresponding Class object from YourTask.class.getClassLoader()
. Do a Class.newInstance() => result is a javax.xml.transform.TransformerFactory
. Call newTransformer on that Factory
That way, you load the correct implementation class name from the Ant typedef
ClassLoader and use directly the javax.xml.transform factory !
Warning: I do not test the code myself. I'm interested to know if you
succeeded.
Hope this helps
Regards
--
Yves Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Typdef/taskdef behaviour and introspection
Posted by Antoine Levy-Lambert <an...@gmx.de>.
Hello Edouard,
I think your problem is the one described in the FAQ
http://ant.apache.org/faq.html#delegating-classloader
the work around is to have your xalan or saxon in the classpath before
starting ant, or to start ant with :
ant -lib [path to xalan]
or
ant -lib [path to saxon]
on top of that, you might really need to do
set ANT_OPTS="-Djava.endorsed.dirs=path to xalan"
because there is a xalan in the JDK 1.4 and higher.
Cheers,
Antoine
> Hi to all;
>
> Having faced a problem too long without precise answer. My problem is the
> following.
>
> I have developed an Ant task that performs XSLT inside. So far, so good,
> provided I put my XSLT implementation in Ant 'lib' directory, the task
> works
> fine.
>
> But as soon as I try to refer to this task via the 'typedef' task with a
> provided classpath that contains both my task jar and the XSLT
> implementation jar (having remove any implementation from Ant 'lib'
> directory at the same time) - this implementation is either
> saxon-6.2.2.jar
> or xalan-2.4.1.jar - the implementation task cannot load.
>
> With Xalan, I get this
>
> javax.xml.transform.TransformerFactoryConfigurationError : Provider
> org.apache.xalan.processor.TransformerFactoryImpl not found
>
> problem, which demonstrates that the JRE cannot find such an
> implementation,
> though it is present in my 'typedef' declaration (for sure).
>
> As I understand, the Java XSLT API performs introspection by creating an
> instance of the 'javax.xml.transform.TransformerFactory' abstract class,
> and
> by looking at the Java system 'javax.xml.transform.TransformerFactory'
> property.
>
> My question is: how to make all this work?
>
> A piece of answer would be: how to force the underlying class loader of
> the
> Ant 'typedef' task to load the whole content of a jar (even those that may
> be used by introspection), instead of just loading the classes declared
> and
> discovered at compile time?
>
> I really need to separate my XSLT implementation and my task from Ant
> 'lib'
> directory!
>
> Thank you very much for your attention, and I hope that a Java class
> loader
> can indicate how to solve that.
>
> Cheers and happy all,
> Edouard
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.809 / Virus Database: 551 - Release Date: 09/12/2004
>
>
>
> ---------------------------------------------------------------------
> 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