JBoss EAR deployment fails because WAR classes are unable to find jars from EAR/lib folder - deployment

I am using JBoss EAP 7 and want to deploy an EAR file in standalone mode (using standalone-ha.xml).
I went through almost everything available on StackOverflow/JBoss forums but couldn't make my deployment to work (correctly). I have followed the docs to the best of my abilities but still the deployment of EAR gives Exception on console because the jar files inside WAR/WEB-INF/lib are not able to see the jar files present int EAR/lib folder. I can't figure out what I am doing wrong.
Structure
myEAR.ear
|- lib (contains a.jar)
|- META-INF
|--- maven (folder with pom)
|--- application.xml
|--- jboss-deployment-structure.xml
|--- MANIFEST.MF
|- myWar.war
|--- WEB-INF
|----- lib (contains b.jar)
|----- jboss-deployment-structure.xml (which should be ignored per the docs)
|----- (WEB-INF contains other files/folders such as classes,jsp etc
EAR- application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" version="7">
<display-name>myear</display-name>
<module>
<web>
<web-uri>myWAR.war</web-uri>
<context-root>/mywar</context-root>
</web>
</module>
<library-directory>lib</library-directory>
</application>
EAR- jboss-deployment-structure.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<deployment>
<dependencies>
<module name="com.organization.global" export="true" />
</dependencies>
</deployment>
<!-- Having/Not having below sub-deployment has no effect -->
<sub-deployment name="myWAR.war">
<dependencies/>
</sub-deployment>
</jboss-deployment-structure>
Deployment succeeds if I copy a.jar inside WAR/WEB-INF/lib/ folder, otherwise gives an exception: Caused by: java.lang.NoClassDefFoundError related to a class specific to a.jar. I want my WAR to be able to get access to all the jars put together inside EAR/lib.
I read in one of the forums that the jar/classes in lib folder should be available to all modules within the EAR but sometimes they are not added automatically but I couldn't find the solution on how to add them.
Any guidance would be appreciated. Thanks in advance!

In JBoss EAP 7, to access lib files present in ear inside war you could try by adding a context param in your war's web.xml.
To create env variable try below in terminal:
export JAR_HOME=../jboss-eap-7.1/standalone/deployments/example.ear(Please add value equivalent to your environment and ear's path)
export PATH=$PATH:$JAR_HOME
Add this variable to web.xml as file:${JAR_HOME}/lib/example.jar
Read this context param inside your classes present inside war.

Related

Jboss eap-7.2: Adding external directory to a class-path

As per project need we need to migrate from jboss-eap-5.1.2 to jboss-eap-7.2 and for testing I was trying to deploy the war file in jboss-7.2.
But it started giving me exception
rom relative location [mailsender.xml]
Offending resource: class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreExcept
ion: IOException parsing XML document from URL [vfs:/C:/dev/migration/jboss-eap-7.2-eap/bin/content/basel.war/WEB-INF/classes/mailsender.xml]; ne
sted exception is java.io.FileNotFoundException: C:\dev\migration\jboss-eap-7.2-eap\standalone\tmp\vfs\temp\tempc01c1475a2367060\content-53d16429
03fec06a\WEB-INF\classes\mailsender.xml (The system cannot find the file specified)
i.e. file mailsender.xml is not added in the classpath.
Query : Is there any way in jboss-eap-7.2 to add a external folder(where I can put all of my XML's which needs to be present at the classpath) to classpath?
This works for me in JBOSS EAP 7.1, where APP-INF/classes resource folder in ear or war:
add META-INF/jboss-deployment-structure.xml with similar config:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<resources>
<resource-root path="APP-INF/classes" />
</resources>
</deployment>
</jboss-deployment-structure>

Copy files to new project and now cannot create JDBC driver of class '' for connect URL 'null'

Caused by: java.sql.SQLException: No suitable driver
A Maven project in eclipse, I lost the .project file for this application. I have to copy the files into another project. So it was running before.
I am using a DataSource in Tomcat. The projects META-INF/context.xml file hasn't changed. It's deployed into /META-INF directory. web.xml and pom.xml is the same. I don't know what has changed. mysql-connector-5.1.38.jar is in $Catalina/lib.
I would look at the Build Path and Deployment Assembly but let me know.
build path.
deployment assly.
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource
name="jdbc/widget"
auth="Container"
type="javax.sql.DataSource"
maxActive="10"
maxIdle="3"
maxWait="10000"
username="appuser"
password="appuserpass"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/widget"/>
</Context>
web.xml
<resource-ref>
<description>MySQL Datasource</description>
<res-ref-name>jdbc/widget</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Coming back to this, I saw a similar project and matched the deployment assembly. This seemed to fix the issue. Current configuration :
/src/main/java -> WEB-INF/classes
/src/main/resources -> WEB-INF/classes
/src/main/resources/META-INF -> META-INF
/src/main/webapp -> /
/src/test/java -> WEB-INF/classes
Maven Dependencies -> WEB-INF/lib

Precedence of EJB Deployment Descriptors

If I have an EJB packaged in a WAR because it is exposed as a REST web service, according to this link, I need to have the ejb-*.xml files at the root of the WEB-INF directory. My current environment is Websphere 8.5 and EJB 3.1
If I later add multiple EJBs ( in separate EJB projects ) in the same application and define its deployment descriptors in the respective projects, those seem to be ignored. It appears that ALL of my descriptors should be defined in the descriptors in the WEB-INF directory - or in other words, it seems that I should augment the descriptors in WEB-INF directory even for EJBs that are defined as separate projects.
Is this how it needs to be or am I missing something that is forcing me to do this? I could not find any documentation explaining this part.
More Details:
This is how my application.xml looks like
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd"
version="7">
<display-name>MyApp</display-name>
<module id="Module_1395346343165">
<web>
<web-uri>MyWeb.war</web-uri>
<context-root>myapp</context-root>
</web>
</module>
<module id="Module_1395346304194">
<ejb>ejb1.jar</ejb>
</module>
<module id="Module_1424684968934">
<ejb>ejb2.jar</ejb>
</module>
<module id="Module_1431010943758">
<ejb>ejb3.jar</ejb>
</module>
</application>
The ejb1 is the one that will live in the webapp. The other two, ejb2 and ejb3 are separate ejb projects that are supposed to be in EAR's root.
For EJBs in a WAR module, the files go in WEB-INF, so .ear!/MyWeb.war!/ejb-jar.xml, .ear!/MyWeb.war!/ibm-ejb-jar-bnd.xml, etc.
For EJBs in separator EJB modules outside a WAR, the files go in META-INF. So, .ear!/ejb1.jar!/META-INF/ejb-jar.xml, .ear!/ejb1.jar!/META-INF/ibm-ejb-jar-bnd.xml, etc.

How to define a custom EAR file name for a specific application?

Here is my setup
SDK: Eclipse Ganymede (3.4.2)
App Server: jBoss 4.2.3GA
I got three projects:
MYAPP, which is the main project, with only libraries and log4j configurations. This is where application.xml and jboss-app.xml resides.
MYAPPEJB, which is my business logic project in which I have my entity beans, sessions beans.
MYAPPWeb, which is my client logic project in which I have my Struts Forms, Struts Actions, JSPs and Jasperreports reports.
When I publish my project to my jBoss server on my laptop, I got the following EAR file name: MYAPP.ear, which make sense.
I would like to define a different custom name for the final EAR, let's say ACCOUNTMANAGER.ear
Here is my application.xml file
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" id="Application_ID" version="5">
<display-name>MYAPP</display-name>
<module>
<ejb>MYAPPEJB.jar</ejb>
</module>
<module>
<web>
<web-uri>MYAPPWeb.war</web-uri>
<context-root>/manager/myapp</context-root>
</web>
</module>
<library-directory>/lib</library-directory>
</application>
Any idea?
Thank you
Charles
You can specify your ear file name in application.xml file under web -> web-uri tag. Please check this link for your reference. web-uri
You can specify in application.xml file. It will pick up this name instead of ear file name.
MyEarName

class def not found in jboss as 7.X

I have a project structure as
eardirectory.Ear
lib/
my-custom-classes.jar
.....
.....
my-custom-ejb.jar
META-INF/
....
//Now I tried to load classes from classloader as
ClassLoader cl = Thread.currentThread().getContextClassLoader();
clazz = Class.forName(my-custom-classes.class1.class.getName(), true, cl);
but this will not work as current thread is of jboss and jboss has not any identification of my-custom-classes.jar.So my question is how this can be done with jboss? I have to have to load class definition at runtime.
Is there any way in "jboss-deployment-structure" I can define how to load classes before deploying EAR?
Follow the steps to create module it should work
Step-1
In jboss-as-7.1.1.Final/modules/com/company/gyani/main/
-module.xml
-my-custom-classes.jar
Content of module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.company.gyani">
<resources>
<resource-root path="my-custom-classes.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
Step-2 Now IN my.ear/META-INF/
-jboss-deployment-structure.xml
-MANIFEST.MF
Content of MANIFEST.MF
Manifest-Version: 1.0
Dependencies: com.company.gyani
You need to use concept of module(s) provided by JBoss AS7.
Here you configure your classes/jars/property files as modules and these are loaded while starting JBoss at server scope and are accessible to any deployed application that carries a dependency on this module.
Read through How to configure module