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.
P.S : 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.
Related
When deploying a war, no issues are there. At run-time, facing java.lang.LinkageError exception.
Details of exception:
Failed to define class javax.wsdl.extensions.soap12.SOAP12HeaderFault in Module
"abc.war:main" from Service Module Loader: java.lang.LinkageError: loader
constraint violation: loader (instance of org/jboss/modules/ModuleClassLoader)
previously initiated loading for a different type with name
"javax/wsdl/extensions/soap12/SOAP12HeaderFault"
How can I check which jars are conflicting and in which class loader?
Stack : Jboss 6, Java 7
A WAR deployment is considered to be a single module in JBOSS 6.
Classes in the WEB-INF/lib directory are treated the same as classes
in WEB-INF/classes directory. All classes packaged in the war will be
loaded with the same class loader.
So problem in WAR packet. You can see all dependency witth mvn dependency:tree command in WAR. If have two or more different version, you should delete one of them.
If there is no conflict in package, probably jboss loaded different your SOAP12HeaderFault version. You can exclude related dependency with jboss-deployment-structure.xml.
<deployment>
<!-- Exclusions allow you to prevent the server from automatically adding some dependencies -->
<exclusions>
<module name="javax.wsdl" />
</exclusions>
</deployment>
UPDATE: This unanswered question on jboss forums, is another way of describing my exact problem: https://developer.jboss.org/thread/199888
Original post:I am trying to make integrated authentication work on web applications deployed to JBoss 7.x. I have successfully made one work, by copying sqljdbc_auth.dll into either Windows/System32, or {java location}/jre/bin. However, if two or more applications are running, I will get an error saying that Native Library sqljdbc_auth.dll already loaded in another classloader
I know why this error is happening, and this question and answer has a Tomcat solution. But I can't make it work in JBoss. Actually, putting the dll inside the jboss/bin folder gives the exact same error as before:
Failed to load the sqljdbc_auth.dll cause :
Native Library C:\Jboss-eap-7.0\bin\sqljdbc_auth.dll already loaded in another classloader
How do I configure JBoss, and/or place the sqljdbc_auth.dll?
My deployments are not located under any module, or named server instance. I think it's simply called standalone
I have tried this approach as well, but I can not figure out where to put the jar file, in the JBoss directories. I tried deploying it as a deployment like the web applications, and I tried copying it into the lib folder, under standalone. No success.
EDIT:
I am trying to implement a global module, as per the answer posted, but get following error now:
14:00:25,333 ERROR [stderr] (ServerService Thread Pool -- 121)
java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver from
[Module "deployment.MyWebapp.war:main" from Service Module Loader]
I assume you must have created a module for sql jdbc driver something like this.
<module xmlns="urn:jboss:module:1.3" name="com.microsoft.sqlserver">
<resources>
<resource-root path="sqljdbc.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
And added this module as dependency to each of your deployed application.
I would suggest to declare this module as global module by editing the standalone.xml file like this ..
<subsystem xmlns="urn:jboss:domain:ee:4.0">
<global-modules>
<module name="com.microsoft.sqlserver" slot="main"/>
.
.
</global-modules>
.
.
</subsystem>
And remove the dependency to this module from your individual applications.
I'm running the following class loading issue with JBOSS.
My JBOSS's module.xml:
<module xmlns="urn:jboss:module:1.0" name="com.example">
<resources>
...
<resource-root path="spring-amqp-1.4.6.RELEASE.jar"/>
...
</resources>
</module>
When org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper:getClassIdType(String classId) is called
MessageConversionException: failed to resolve class name... is thrown by
ClassUtils.forName(classId, getClass()
.getClassLoader())
Debugging getClass().getClassLoader() returns ModuleClassLoader for Module "com.example:main".
So it seems the issue is the class I'm deserializing is not in module com.example (defined in module.xml) so it throws that exception
Myjboss-deployment-structure.xml has com.example as a dependency:
<dependencies>
<module name="com.example">
<imports>
<include path="META-INF**"/>
</imports>
</module>
</dependencies>
I can fix this problem if I remove spring-amqp-1.4.6.RELEASE.jar from module.xml and add spring-amqp to my build.gradle. Problem is module.xml is shared across my org and I can't change that.
So how can I fix this? Appreciate any help.
A stacktrace (and some more code) to reproduce would be nice. I am not familiar with amqp.
In https://github.com/spring-projects/spring-amqp/blob/master/spring-amqp/src/main/java/org/springframework/amqp/support/converter/DefaultJackson2JavaTypeMapper.java at line 56, ClassUtils.forName(classId, getClass().getClassLoader()) gets called, but can't find the class.
In JBoss, module classloaders are seperated from application classloaders. In your application, you can access all classes from the module, but the module can't access your WAR or JAR classes.
So, this is exception is thrown, because your module, tries to load a class from your application, which is not visible in the module classloader. But if you add the amqp-jar to your application, it works, because they share the same classloader.
If you want/need amqp in a module, you need to create a module with your application common-classes and add it to your module as a dependency. But also note, you can't add the common.jar to the application.jar anymore to avoid classCastExceptions.
I don't know, how amqp is used, but probably, you need to create multiple modules to use it with different common.jars.
For more information about jboss classloading, i can refer you to:
http://www.mastertheboss.com/jboss-server/jboss-as-7/discover-jboss-as-7-modularity
https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6/html/Development_Guide/chap-Class_Loading_and_Modules.html
I have a dependency JAR that i copy into APP-INF/lib directory which is listed in application.xml file as <library-directory>APP-INF/lib</library-directory>
When ever i try to start the server i get following error
Can anybody please help me solve this problem.
Have a look at:
https://docs.jboss.org/author/display/WFLY8/Class+Loading+in+WildFly
Our deployment structure looks essentially like this:
my.ear
+ lib/ <-- dependencies for multi-submodule deployment
+ META-INF/ <-- application.xml defines submodule(s) e.g. web.war,
<-- also jboss-deployment-structure.xml to include/export wildfly core modules for your EAR
+ web.war <-- our core deployment
I think in your case, you could just deploy your JARs to EAR/lib and they should be found across all submodules. From the Wildfly docs "Sub deployments (wars and ejb-jars) always have a dependency on the parent module, which gives them access to classes in EAR/lib"
I am trying to build a sar archive that contains an MXBean and deploy it in JBoss 7.
Until recently I had a problem referencing classes from other libraries in my MXBean class because JBoss wouldn't load those libraries no matter where in the SAR archive I'd put them.
I found out that one can configure the classpath of a SAR through the jboss-deployment-structure.xml file placed in META-INF. My version of this file looks like this:
<jboss-deployment-structure>
<deployment>
<resources>
<resource-root path="management.api.jar" />
</resources>
</deployment>
Now the classes from the "management.api.jar" are loaded.
The problem I am now facing is the following: If the interface of the MXBean is stored in the management.api.jar and the class implementing it is directly in the SAR archive, then, when JBoss reads the jboss-service.xml and tries to create the mxbean it yields a ClassNotFoundException pointing to the interface (that is in the management.api.jar). Hence, although classes from the external jar are loaded ok (i tested this by actually invoking a method that referenced a class from the jar and it worked), it seems that when JBoss registers the bean, it doesn't go through the whole classpath as defined in the jboss-deployment-structure.xml.
I am currently stuck and I suspect this to be a bug in the way JBoss handles the class loading. If anyone knows a way around this (other than taking the interface out of the jar and putting it in the SAR archive directly, cause this will break the whole "api" idea) please let me know.
Thanks!
When I understand it right, the management api should be used in different projects and should be global in the server. A simple workaround can be to put your jar in the module-folder of your jboss. Therefor create a module.xml like this below and put it with your jar in a extra-folder main in the jboss7/modules/yourfolder.
(In the module folder the jboss 7.1 stores all libs.)
<!-- defines the name of your lib -->
<module xmlns="urn:jboss:module:1.1" name="yourfolder">
<resources>
<!-- the jar in your main folder-->
<resource-root path="management.api.jar"/>
<!-- Insert resources here -->
</resources>
<dependencies>
...dependencies of your api
</dependencies>
</module>
Then you can load the dependency from your sar-jboss-deployment-structure by
<dependencies>
<module name="yourfolder" slot="main" export="true"/>
</dependencies>
The slot=main means that you use the the folder main, you can add different versions, like 1.1 and so on. Main is also the default slot, you can leave it out.
If your folder-structure goes into deep, simple define and include the modules like packages.
In that way you can define api.jars in the jboss and reference it from several projects.