Rupesh
Rupesh

Reputation: 301

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

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!

Upvotes: 0

Views: 2451

Answers (1)

Sweta Patra
Sweta Patra

Reputation: 351

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.

Upvotes: 1

Related Questions