On 10/19/2010 09:49 AM, Stian Soiland-Reyes wrote:
> On Mon, Oct 11, 2010 at 18:52, Jason Reilly<[email protected]>  wrote:
>    
>> Hi,
>>
>> I wrote a Taverna2 plugin to call into a set of web services&  am
>> getting the following exception:
>>
>> org.apache.axiom.om.OMException: java.lang.ClassNotFoundException: 
>> org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory
>>
>>      at 
>> org.apache.axiom.om.OMAbstractFactory.getOMFactory(OMAbstractFactory.java:61)
>>      
> This getOMFactory() method does not seem to be written for systems
> with more than one classloader, such as in Taverna's plugin system.
>
>   public static OMFactory getOMFactory() {
>          if (defaultOMFactory != null) {
>              return defaultOMFactory;
>          }
>          String omFactory;
>          try {
>              omFactory = System.getProperty(OM_FACTORY_NAME_PROPERTY);
>              if (omFactory == null || "".equals(omFactory)) {
>                  omFactory = DEFAULT_OM_FACTORY_CLASS_NAME;
>              }
>          } catch (SecurityException e) {
>              omFactory = DEFAULT_OM_FACTORY_CLASS_NAME;
>          }
>
>          try {
>              defaultOMFactory = (OMFactory)
> Class.forName(omFactory).newInstance();
> ..
>          return defaultOMFactory;
>      }
>
> Class.forName() - loading a class by string from the callers
> classloader - would not work very well.
>
> The reason is that OMAbstractFactory is in axiom-api, and
> OMLinkedListImplFactory in axiom-impl - but in Raven (Taverna's plugin
> system) each Maven module gets a dedicated classloader that can only
> see classes from its own dependencies. So this would have worked with
> the good-old java -classpath a.jar:b.jar - but not within a
> hierarchical plugin system, where Class.forName() will use the
> classloader of axiom-api to look for
> org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory -
> unsuccessfully.
>
>
>
> It seems OMAbstractFactory does not allow a way to set this class
> except as a system property, but that classname would still only be
> loaded from the axiom-api classloader. The 'correct' way to load
> classes dynamically in a plugin environment would be to use
> Thread.currentThread().getContextClassLoader(), a class loader passed
> in to the getOMFactory() method - or allow the setting of the instance
> directly using a setter method. As the field "defaultOMFactory" is
> private, it would be tricky for you to make a subclass of
> OMAbstractFactory to fix this.
>
> I guess unfortunately Axiom is not your product, and you just want to
> use it - so fixing that sourcecode is probably not your main
> priority...
>
>
> I see from your stack trace that you are the one using the factory -
> so in theory you could do new OMLinkedListImplFactory(); directly
> instead of calling getOMFactory - but if other code in Axiom tries to
> use the getOMFactory() method it would probably fall over later.
>
>  From what I can see calls to getOMFactory()  happens at various places
> inside Axiom, so it will probably not work - but worth a try.
>
>
>
> There's two hacks you can do to work around this.
>
> 1) Modify the POM file of axiom-api and axiom-impl to force a circular
> dependency - so axiom-api depends on axiom-impl. Not sure if this
> would work. You would need to use different version numbers and deploy
> these modified versions to your Maven repository.
>
> 2) Merge the two JARs into an axiom.jar - and deploy this separately
> with its own POM. This POM should not depend on axiom-api or
> axiom-impl - but should depend on everything else those two have in
> their POM. Again you would need to deploy this yourself - you should
> indicate strongly in the version name that this is your own version -
> like 1.2.8-renci
>
>
> Once Taverna moves to use OSGi for its plugin system (post 2.3) it
> should be easier to avoid these kind of problems - you could have just
> a single OSGi bundle for your plugin, which could include both
> axiom-api, axiom-impl and your own code on the same classloader.
>    

I look forward to the OSGi version to be release (I have some experience 
with Felix/Karaf).

As an alternative to the above options, do you see any problems with 
just copying over dependencies to the 'T2_HOME/lib' directory?

Thanks,
Jason





------------------------------------------------------------------------------
Download new Adobe(R) Flash(R) Builder(TM) 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder(TM) 4 (formerly 
Flex(R) Builder(TM)) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
_______________________________________________
taverna-users mailing list
[email protected]
[email protected]
Web site: http://www.taverna.org.uk
Mailing lists: http://www.taverna.org.uk/about/contact-us/

Reply via email to