Migration to JBoss7.2eap from jboss5.1.2eap : java.lang.NoClassDefFoundError: Lorg/apache/commons/dbcp/BasicDataSource - jboss

I have migrated my application from jboss5.1.2-eap to jboss-7.2-eapand java6 to java8 but after migration it is starting giving me exception while starting the server.
Caused by: java.lang.NoClassDefFoundError: Lorg/apache/commons/dbcp/BasicDataSource
we have a datasource.xml file present in the classpath of the server, having the following line of code.
<bean id="beanName" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="maxActive" value="10"/>
Also we have commons-dbcp-1.2.2.jar present in the classpath but it is not working for jboss-7.2-eap.
Now I am not sure if commons-dbcp-1.2.2.jar is supported by jboss7-eap. as it is present in the classpath of the application(present in the loaded module), but still spring is not able to create the bean for datasource.

I suppose that datasource in Jboss EAP should be placed in standalone.xml configuration file and looks like here:
<datasource jndi-name="java:jboss/datasources/Altis" pool-name="Altis" enabled="true">
<connection-url>jdbc:oracle:thin:#255.255.255.255:1521:sid</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>oracle</driver>
<security>
<user-name>username</user-name>
<password>passwd</password>
</security>
</datasource>

Given module information in the jboss-deployment-structure.xml inside the WEB-INF directory of the war file.
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.oracle.sql" export="true"/>
<module name="org.apache.commons.dbcp" export="true"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
Also the module directories should also follow the same naming convention as per the availability of your .class files inside the jar, like in my case I have created module org.apache.commons.dbcp as while opening commons-dbcp-1.2.2.jar file, .class files are present inside org/apache/commons/dbcp folder.
Note: In case of multiple modules, you need to identify there dependency if a module is dependent on other and that information will be given inside module.xml file. like
<module xmlns="urn:jboss:module:1.1" name="org.apache.commons.dbcp">
<resources>
<resource-root path="commons-dbcp-1.2.2.jar"/>
</resources>
<dependencies>
<module name="org.apache.commons.pool"/>
<module name="com.oracle.jdbc.driver"/>
</dependencies>
</module>

Related

Context root automatically changing to temp folder name in JBOSS EAP 6.4

I have an application that I am trying to deploy to JBoss EAP 6.4. I don't see any errors while deploying the application. However, when I try to access the application with the context root like http://localhost:8080/contextroot/ I am being redirected to http://localhost:8080/contextroot.war-345rdser34dwwe/login.jsp where contextroot.war-345rdser34dwwe is a folder created under ${jboss.home}/standalone/tmp/vfs/temp
This is my jboss-deployment-structure.xml
<jboss-deployment-structure> <!-- Make sub deployments isolated by default, so they cannot see each others
classes without a Class-Path entry -->
<ear-subdeployments-isolated>false</ear-subdeployments-isolated> <!-- This corresponds to the top level deployment. For a war this is the
war's module, for an ear --> <!-- This is the top level ear module, which contains all the classes in
the EAR's lib folder -->
<deployment>
<resources>
<resource-root path="WEB-INF/lib/bcprov-jdk16-1.46.jar" use-physical-code-source="true"/>
</resources>
<!-- exclude-subsystem prevents a subsystems deployment unit processors running
on a deployment --> <!-- which gives basically the same effect as removing the subsystem, but
it only affects single deployment -->
<exclusions>
<module name="org.javassist" />
<module name="org.hibernate" />
<module name="org.hibernate.validator" />
<module name="org.jboss.msc" />
<module name="javax.faces.api" />
<module name="com.sun.jsf-impl" />
<module name="org.apache.log4j" />
<module name="org.slf4j" />
<module name="org.slf4j.impl" />
<module name="org.apache.commons.logging" />
<module name="org.jboss.resteasy.resteasy-hibernatevalidator-provider" />
</exclusions>
<!-- This allows you to define additional dependencies, it is the same as
using the Dependencies: manifest attribute -->
<dependencies>
<module name="com.company.app.config" optional="TRUE"/>
<module name="deployment.module.nested.app"/>
</dependencies>
</deployment>
<module name="deployment.module.nested.app">
<resources>
<resource-root path="../contextroot.war"/>
</resources>
</module>
This is my jboss-web.xml
<!DOCTYPE jboss-web PUBLIC
"-//JBoss//DTD Web Application 4.2//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
<jboss-web>
<security-domain>UserModule</security-domain>
<security-domain>ServiceModule</security-domain>
</jboss-web>
This is my config in standalone-ha.xml for security subsystem
<security-domain name="UserModule" cache-type="default">
<authentication>
<login-module code="com.company.uas.service.authentication.loginmodule.UserLoginModule" flag="required"/>
</authentication>
</security-domain>
<security-domain name="ServiceModule" cache-type="default">
<authentication>
<login-module code="com.company.uas.service.authentication.loginmodule.ServiceLoginModule" flag="required"/>
</authentication>
</security-domain>
I have been working on it for couple of days now but could not find anything online related to this issue.
I am not sure if I consider this an answer but I understood why my /contextroot was changing to /contextroot.war-345rdser34dwwe. This was because, I was deploying a war file to JBoss and JBoss was pointing to the exploded version of my war file which was present in the tmp folder for some reason.
I deployed an exploded version of my war file with the name contextroot.war as the name of the folder and it worked.

loading shared native modules from ear file than from web apps in JBoss environment

There is a jar which loads native libraries .so files. This jar is available as a jboss module on the server. Native files can be loaded only once per classloader.
There are two war modules war1, war2 inside an ear1 file. if the module is configured as jboss module in both war1 & war2, I have no issues. But I am looking for an alternative where if i configure the jar which is loading the native library in the earfile/lib and the war refers from there, does that work. That particular class should load only once and shoudl be available in both the war files.
Solution:
We need to add sub-deployment section to the jboss deployment xml file inside ear/Meta-INF folder. That way the jboss module can be made available to all other submodules/war modules.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.aexp.sec.crypto" export="TRUE" />
</dependencies>
</deployment>
<sub-deployment name="crypto-war1-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>
<sub-deployment name="crypto-war2-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
Note: For the Benefits of the future users, adding the solution of #Vamshidhar Cheburthy below,
We need to add sub-deployment section to the JBoss deployment XML file inside ear/Meta-INF folder. That way the JBoss module can be made available to all other submodules/war modules.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.aexp.sec.crypto" export="TRUE" />
</dependencies>
</deployment>
<sub-deployment name="crypto-war1-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>
<sub-deployment name="crypto-war2-1.0-SNAPSHOT.war">
<dependencies>
<module name="com.aexp.sec.crypto" />
</dependencies>
</sub-deployment>

classloading problems with Wildfly 8.0.0

I am trying to deploy a Spring-JPA-Hibernate web application on Wildfly. First, I had problems with Hibernate which seemed to go away with
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.hibernate" slot="main" />
</exclusions>
<dependencies>
<module name="org.hibernate" />
</dependencies>
</deployment>
</jboss-deployment-structure>
then however, my org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean tried to parse its mappingResources (xml file), and I got the exception
Error while parsing (.... etc)
org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.buildHibernateConfiguration(EntityManagerFactoryBuilderImpl.java:1163)
... 44 more
Caused by: org.dom4j.DocumentException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
which seems to suggest there is another dom4j on the classpath.
At this point I got lost, since tinkering again with jboss-deployment-structure.xml only made the server freeze with no error message soon after startup.
Is there a simple way just to tell Wildfly not to put on the classpath at least its dom4j (or better, not to add anything at all automatically)?
I think that you must choose a strategy to use the classes from Wildfly or to use the classes you provide in your application.
I have the similar issue with Liferay 6.2 GA3 deployed in Wildfly 8.2. I solved it using a deployment descriptor similar to:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0">
<deployment>
<exclusions>
<module name="org.apache.log4j"/>
<module name="org.hibernate"/>
<module name="org.hibernate.validator"/>
<module name="org.jboss.as.jpa"/>
<module name="org.javassist"/>
<module name="javaee.api"/>
</exclusions>
<dependencies>
<!-- add the module and remove the dom4j in your application
or exclude the module and add the jar in your application -->
<module name="org.dom4j"/>
<module name="javax.mail.api"/>
<module name="org.apache.xerces"/>
<module name="org.jboss.modules"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
https://www.liferay.com/community/forums/-/message_boards/view_message/40321431#_19_message_47754919
If you want to use the Wildfly classes and deploy the JPA entities in Wildfly container, use a similar persitence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="MyApp" transaction-type="JTA" >
<!-- Data Source -->
<jta-data-source>java:jboss/datasources/MyApplicationPool</jta-data-source>
<!-- Class -->
<class>entities here </class>
<!-- Properties -->
<properties>
<!-- the persitence unit will be deployed in Wildfly and linked to spring
using JNDI https://docs.jboss.org/author/display/WFLY8/JPA+Reference+Guide#JPAReferenceGuide-BindingEntityManagerFactory%2FEntityManagertoJNDI -->
<property name="jboss.entity.manager.factory.jndi.name" value="java:jboss/WildflyEntityManagerFactory" />
<property name="jboss.entity.manager.jndi.name" value="java:/WildflyEntityManagerVMS" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<!-- for the JODA datetime -->
<property name="jadira.usertype.autoRegisterUserTypes" value="true" />
</properties>
</persistence-unit>
Make reference to the Wildfly persitence unit in your Spring application:
<bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<jee:jndi-lookup id="entityManagerFactory"
jndi-name="java:jboss/WildflyEntityManagerFactory" expected-type="javax.persistence.EntityManagerFactory" />
And you should not need any specific jboss-deployment-structure.

Why does my JBoss module throw a ClassCastException?

Hi StackOverflow Community,
I have a WAR which I have deployed to a JBoss Wildfly 8.2 instance. Also in Wildfly, I have created two modules:
a third party JMS JCA adapter module,
and a model module (model.jar) that contains message classes used to communicate between the JMS broker and the WAR
The WAR has a jboss-deployment-structure.xml that declares a dependency on the JCA module:
<?xml version='1.0' encoding='UTF-8'?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<dependencies>
<module name="com.thirdparty.mq.ra" slot="main"/>
<module name="com.company.model" slot="main">
</dependencies>
</deployment>
</jboss-deployment-structure>
The WAR has the model.jar file packaged in its WEB-INF/lib folder.
The JMS module has a dependency on the model module:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="com.thirdparty.mq.ra">
<resources>
<resource-root path="."/>
<resource-root path="thirdparty-jms-provider.jar"/>
...
<resource-root path="thirdparty-lib.jar"/>
</resources>
<dependencies>
<module name="com.company.model"/>
<module name="javax.api"/>
<module name="javax.jms.api"/>
<module name="javax.transaction.api"/>
<module name="javax.management.j2ee.api"/>
<module name="javax.resource.api"/>
<module name="org.jboss.invocation"/>
<module name="org.jboss.remote-naming" optional="true"/>
<module name="org.slf4j"/>
</dependencies>
</module>
When running, I get the following exception:
Caused by: java.lang.ClassCastException: com.company.model.web.dto.WebAuthenticationResponse cannot be cast to com.company.model.web.dto.WebAuthenticationResponse
I suspect it is a classloader issue. Is there some extra information I have to specify in the module.xml or jboss-deployment-structure.xml files?
Thanks for your help!
Assuming that your model.jar corresponds to your com.company.model module, your WAR classloader now sees the model classes twice, both from its own libraries in WEB-INF/lib and via the module dependency.
You should either import or embed a module/library, but not both.
By the way, importing a RAR module looks a bit suspicious. You should never depend on the implementation of a resource adapter. Maybe you can factor out an API module and import that.

Path setting for DLL's in JBOSS 7.1.1

We have some DLL's which are related to Java,VB. In Joss 4.X , We used to place in bin directory under Application Server.
We migrated to JBOSS 7.1.1 and when I removed from bin directory and placed them in libraries folder under C:\jboss-as-7.1.1.Final\modules\com\correction\main\libraries .
I am getting this exception
java.lang.UnsatisfiedLinkError: no xxxJavaWrapper in java.library.path
java.library.path = C:\Program Files\Java\jdk1.6.0_24\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\apache-maven-3.0.4;C:\apache-maven-3.0.4\bin;C:\Python27;C:\Program Files\Java\jdk1.6.0_24;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
java.lang.UnsatisfiedLinkError: com.xxxJavaWrapperJNI.new_xxx()J
module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.correction">
<resources>
<resource-root path="xxx.jar"/>
<resource-root path="xyz.jar"/>
<resource-root path="libraries"/>
</resources>
<dependencies>
<system export="true">
<paths>
<path name="libraries"/>
</paths>
<exports>
<include-set>
<path name="libraries"/>
</include-set>
</exports>
</system>
</dependencies>
</module>
But I place the same dll's in bin folder, it is working fine.
I want to place them in module folder and set the path from there instead of bin so that I can have all the application related jar's, properties and dll files at one place for ease maintainance.
Also I want to know how to set the path of txt and properties files in jboss 7.1.1
Regards
Srini
Configure module.xml as below:
<module xmlns="urn:jboss:module:1.1" name="com.correction">
<resources>
<resource-root path="xxx.jar"/>
<resource-root path="xyz.jar"/>
<resource-root path="lib/win-x86_64"/>
</resources>
<dependencies>
<module name="sun.jdk"/>
</dependencies>
</module>
Put the DLLs into the directory lib/win-x86_64. Check the another dependencies of your project.
In WEB-INF of your application creating the file jboss-deployment-structure.xml and put the content below:
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.correction"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
That's all.
Another Question: How can you make these properties files accessible to applications deployed on JBoss 7?
create a custom module where you put your properties files and put jboss-deployment-structure.xml to your application archive (WAR/EAR) to use that custom module.
Create the new module directory under $JBOSS_HOME/modules(using app/conf in this example)
mkdir -p $JBOSS_HOME/modules/app/conf/main/properties/
Put your properties files in $JBOSS_HOME/modules/app/conf/main/properties/
Create a module.xmlhere $JBOSS_HOME/modules/app/conf/main/module.xml
<module xmlns="urn:jboss:module:1.1" name="app.conf">
<resources>
<resource-root path="properties"/>
</resources>
</module>
put the following jboss-deployment-structure.xml in WEB-INF:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="app.conf" />
</dependencies>
</deployment>
</jboss-deployment-structure>
Then you can access your properties files using thecode below (example assumes you have a
example.propertiesfile in $JBOSS_HOME/modules/app/conf/main/properties/)
Thread.currentThread().getContextClassLoader().getResource("example.properties");
Ps: I used JBoss AS 7.1.2 ( JBoss EAP 6 )
Regards
Mauricio Magnani