0

I have an .aar file deployed on Tomcat,Axis2 platform in Ubuntu. I'm using Oracle JDK1.7 Tomcat 7.0.35 and Axis2 1.6.2

Recently I made a refactoring to use java.util.ServiceLoader class to load implementations of some classes dynamically.

Here is my aar file structure:

META-INF folder

services.xml Contains info about the web service

services folder
    com.companyname...interfacename1 (contains implementation class name)
    com.companyname...interfacename2 (contains implementation class name)
    com.companyname...interfacename3 (contains implementation class name)

com folder
    companyname folder
        bla bla.class compiled class files here

In my Eclipse Development environment, my methods run w/o any problem but when they run in Axis2 Tomcat platform, ServiceLoader class can not load implementation classes. What can be the problem? Any help is appreciated. Thanks.

  • In Apache Axis2 FAQ page [link](http://axis.apache.org/axis2/java/core/faq.html), There is a recommandation for accessing a service class loader using Axis API like this: AxisService myService = messageContext.getAxisConfiguration().getAxisService("serviceName"); AxisService myService = msgCtx.getAxisService(); ClassLoader clsLoader = myService.getServiceClassLoader(); Then I can invoke like this: ServiceLoader.load(service,clsLoader) Thanks to Deepal Jayasinghe for the recommendation! However, this code brings Axis2 package dependencies to my code. Is there an improved way to do this? – Bulent Ozhorasan Jan 27 '13 at 07:05

1 Answers1

0

Just use one of your classes to obtain their classLoader,Then use it:

    ClassLoader classLoader = com.companyname.blabla.MyClass1.getClassLoader();

    java.util.ServiceLoader.load(blabla.class,classLoader);

It works both in Tomcat,Axis2 deployed code and in development environment unit test code!