简体   繁体   中英

Wildfly Class Loading issue with jca resourceadapter

I am trying to deploy an ear application on wildfly 9 that tries to connect to MQ and to a JCA resource adapter.

Structure of my ear file

 myApp.ear
    |--lib/
    |----Spring.jar (Multiple jars for different modules needed)
    |----META-INF/
    |--myAppEJB.jar (EJB project)
    |--myAppWeb.war 
    |--jboss-deployment-structure.xml

The JCA resource adapter (myCompConnector.rar) is packaged as a rar and deployed with an ra.xml inside it. myCompConnector uses two jars supportingjar1.jar and supportingjar2.jar and are packaged inside the rar file. Structure of my MyCompConnector.rar:

MyCompConnector.rar
|--META-INF
|--supportingjar1.jar
|--supportingjar2.jar
|--MyCompConnector.jar

my application also uses the classes that are in myCompConnector but is compiled with myCompConnector.jar. I make the build using maven 3 and I do not package the myCompConnector.jar or any depending jars.

If i deploy it says that NoClassDefFoundError for a class in supportingjar1.jar, So i add ONLY the supporting jars by putting in the lib of the ear myApp.ear (making the war a skinny war as well supporting jars are only used in the EJB project's pom file not in WAR)

Then If i deploy it on wildfly it says NoClassDefFoundError MyCompConnectorInspector.java and ClassNotFoundError MyCompConnectorInspector.java. MyCompConnectorInspector is a class in the MyCompConnector.jar which is also present in MyCompConnector.rar.

Caused by: java.lang.NoClassDefFoundError: Lcom/myComp/MyCompConnector/MyCompConnectorInspector ;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2317)
    at java.lang.Class.getDeclaredFields(Class.java:1762)
    at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57)
    at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66)
    ... 10 more
Caused by: java.lang.ClassNotFoundException: com.mycomp.MyCompConnector.MyCompConnectorInspector from [Module "deployment.myApp-1.3.ear.myAppEJB-1.3.jar:main" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:205)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:455)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:404)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:385)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:130)
    ... 15 more

So I add MyCompConnector.jar as well in the lib folder of the ear file (So now my MyCompConnector.rar is loaded and MyCompConnector.jar is loaded from the lib folder in the ear file)

If i deploy now it says ClassCastException: com.comp.MyCompConnector.MyCompConnectorInspector.java cannot be cast to com.comp.MyCompConnector.MyCompConnectorInspector.java

which is true as it is loaded from two sides. Now i cannot remove the rar resource adapter so if i remove the jar file from the lib of the ear it says the above mentioned error: NoClassDefFoundError MyCompConnectorInspector.java and ClassNotFoundError MyCompConnectorInspector.java.

So now i am in a fix. If i add the jar to remove the NoClassDefFoundError it will give me classcast exception.

In the event of the class cast exception I see that MyCompConnectorInspector is loaded from the RAR's MyCompConnector.jar (when i do -verbose=class) but when i remove the jar file from the myApp/lib/ then i do not see MyCompConnectorInspector being loaded from the RAR's MyCompConnector.jar.

my jboss-deployment-structure in the ear file looks like this:

<?xml version="1.0" encoding="UTF-8"?>   
<jboss-deployment-structure>   
    <deployment>   
        <dependencies>   
            <module name="MyCompConnector.rar" />
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
            <module name="javax.jms.api"/>
            <!--<module name="com.compConnector.supportingjar1"/>
            <module name="com.compConnector.supportingjar2"/>   -->

       </dependencies>
    </deployment>   
</jboss-deployment-structure>

How can I make the rar deployment seen as something that my ear file should refer to as a library as well as all he dependent libraries included in the RAR.

one more question: when i deploy a RAR, is it technically a module. (Modules are a new concept for me from Jboss 5 or websphere which i have worked with before)

One funny thing that I have seen, If i use

<module name="deployment.MyCompConnector.rar" />

that I have seen in some expamples in any Resource Adapter definition it does not load at all. if i remove the deployment. then it creates the jndi name for it and binds it. I dont know if it is related tough. Any help will be appreciated. I am new to Wildfly so I am still learning its tricks.

Thanks.

PS : I even tried to do

<global-modules>
                <module name="deployment.MyCompConnector.rar" />            
            </global-modules>

but it only gave me Failed to load module: deployment.MyCompConnector.rar:main Then ModuleNotFoundException : deployment.MyCompConnector.rar:main

i deployed the rar through the console and not through creating a module in the modules folder and then added a connection definition in the resourceAdppaters in the standalone-full.xml . this is the same I deployed the wmq.jmsra.rar file and then made the connection definition.

It seems there is an issue in Wildfly when a resource adapter is being referenced from within a jar (in modules) or from a jar inside an ear. In a war it works fine. I may be mistaken when i assume there is an issue in WF9. but i made it to work. I had this issue in case of an ear as well as a jar.

in case of ear I simply converted the ear into a war and pluggged my EJBs into the War's WEB-INF/lib folder as a jar. and it worked without any issues.

Hopefully it will help some one who has a RAR resource adapter and is using the resource adapter'sconnection classes as library inside the EJBs of an ear project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM