How to deploy one .war after another on JBoss - java

Is there a way to define order of .war deployments on JBoss 7?
What I would like to accomplish is that on startup of JBoss it first deploys .war A and then .war B.
I need this because .war A is a service which is consumed on a startup of .war B!

You have to specify the dependency on the B war by creating a jboss-all.xml file on the META-INF folder,with a content like this:
<jboss umlns="urn:jboss:1.0">
<jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0">
<dependency name="A.war" />
</jboss-deployment-dependencies>
</jboss>
The procedure is explained here Control the order of Deployed Applications on JBoss

As mentioned in this JBoss's Forum thread, in order to ensure that A.war is deployed first than B.war, you should create a MANIFEST file under your B.war's src/main/webapp/META-INF folder, with the following entry:
dependencies: deployment.A.war
Furthermore, if you need to access A.war classes from B.war, you should also add a jboss-deployment-structure.xml, under your B.war's src/main/webapp/WEB-INF folder, with the following contents:
<?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"
xsi:schemaLocation="urn:jboss:deployment-structure:1.2 http://www.jboss.org/schema/jbossas/jboss-deployment-structure-1_2.xsd">
<deployment>
<dependencies>
<module name="deployment.A.war" export="true"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
You can also take a look at JBoss AS 7 class loading documentation.

Related

Is it possible to use environment variables while declaring jboss-deployment-structure.xml

I want to have this sort of jboss-deployment-structure.xml :
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
<resources>
<resource-root path="{PROPERTY_FILE_LOCATION}" />
</resources>
</deployment>
</jboss-deployment-structure>
By this, I want property files placed at the location defined by the environment variable PROPERTY_FILE_LOCATION to be loaded in the classpath. Is it possible to do this? I'm using JBoss 6.4
My entire purpose here is to get my property files placed in an external location, to be loaded into the classpath by JBoss (the files are being used in a jar that I cannot modify). I don't want to hardcode the location either.

Jboss EAP 7 - How to exclude implicit modules from deployment (javax.jms)?

I didn't think I would end up here but after a lot of Google and StackOverflow searches here I'm.
This is my exact problem except that I can't afford to make code changes.
The WAR I'm trying to deploy includes a JMS library (i.e. javax.jms, which I cannot exclude form the WAR.) which is already loaded by Jboss EAP 7 by default. The path to jar is something like this jboss/modules/system/layers/base/javax/jms/api/ain/jboss-jms-api_2.0_spec-1.0.0.Final-redhat-1.jar. Because of this two different versions of the same classes loading I'm getting ClassCastException.
org.apache.activemq-ra.ActiveMQConnectionFactory cannot to be cast to javax.jms.ConnectionFactory
So, I want Jboss to NOT load javax.jms so that my application can use the JAR included with the WAR.
So, I was wondering if there was any way to exclude the module globally (for all WAR deployments).
Excluding it per deployment would work too. And I do realize it can be acheivd using jboss-deployment-structure.xml but I can't get it to work.
Here is what I tried:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure
xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclude-subsystems>
<subsystem name="javax" />
<subsystem name="javax.jms" />
</exclude-subsystems>
</deployment>
</jboss-deployment-structure>
and
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure
xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclusions>
<module name="javax" />
<module name="javax.jms" />
<module name="javax.jms.api" />
</exclusions>
</deployment>
</jboss-deployment-structure>
I placed the file in WEB-INF directory. It didn't work. It still loaded the JMS class from modules folder of Jboss EAP. So, how do I correctly do this?
The correct jboss-deployment-structure.xml is here:
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclude-subsystems>
<subsystem name="messaging-activemq"></subsystem>
</exclude-subsystems>
<exclusions>
<module name="javax.jms.api"></module>
</exclusions>
</deployment>
</jboss-deployment-structure>
This way you exclude both messaging subsystem and the JMS api.
You should remove the JMS API JAR from your deployment. You can still keep the JMS implementation JAR in your deployment but that should probably end up in a RAR, preferably outside your deployment.
This link has some things you could try.
Notably:
I think the problem is that activemq-all-5.4.2.jar contains javax.jms.*. Your deployment already gets this implicitly from the javaee.api module (see more information about implicity module dependencies here). I don't think it is appropriate for an application module/jar to package Java EE interfaces. You can try simply deleting the javax directory from activemq-all-5.4.2.jar or using a different set of ActiveMQ jars in your module to limit it to only what you need.
and/or altering your module.xml for ActiveMQ
<module xmlns="urn:jboss:module:1.0" name="activemq">
<resources>
<resource-root path="activemq-all-5.4.2.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
There appears to be a method to embed ActiveMQ in Jboss as well, if you're interested. I won't pull out information from that article, as it doesn't answer the original question.

Can't able to deploy EAR on JBoss 8 WildFly

I tried to deploy an EAR file into the JBoss WildFly server, but it is not deploying the EAR file.
Steps that I followed:
Copy the EAR file and paste into jboss_dir/standalone/deployments location.
Run the command jboss_dir/bin/standalone.bat
If I put the JAR or WAR file than JBoss server can able to deploy.
Kindly help me out to fix this issue.
In JBoss 4.2 I just copy EAR file into the default/deploy folder and it is able to deploy, but I want to deploy EAR file into JBoss WildFly.
You need to place the application.xml deployment descriptor in META-INF inside the ear.
<?xml version="1.0" encoding="UTF-8"?>
<application version="7" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee">
<display-name>Your-ear-name</display-name>
<module>
<java>Your-jar-1</java>
</module>
<module>
<java>Your-jar-2</java>
</module>
<library-directory>lib</library-directory>
</application>

JBoss EAP 7 => ClassCastException: org.apache.jcp.xml.dsig.internal.dom.DOMReference cannot be cast to org.jcp.xml.dsig.internal.dom.DOMReference

I am getting this error:
java.lang.ClassCastException: org.apache.jcp.xml.dsig.internal.dom.DOMReference cannot be cast to org.jcp.xml.dsig.internal.dom.DOMReference
Maybe the problem is on the jboss-deployment-structure.xml of the servlet:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
<deployment>
<dependencies>
<module name="javax.api"/>
<module name="org.apache.santuario.xmlsec"/>
<module name="org.apache.xerces" />
<system export="true">
<paths>
<path name="com/sun/org/apache/xerces/internal/dom"/>
</paths>
</system>
</dependencies>
</deployment>
</jboss-deployment-structure>
Do you have any hint of whats going on?
Thanks in advance.
Your problem is different xmlsec library version.
org.apache.jcp.xml.dsig.internal.dom.DOMReference located in xmlsec-1.5.1.jar (org.apache.santuario.xmlsec module in JBoss)
org.jcp.xml.dsig.internal.dom.DOMReference located in xmlsec-1.4.3.jar (dependency in your pom.xml)
Jboss 7 uses isolated modules https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7 it is complicated and i really don't know how it works inside.
But if simplify, when jboss start, it loads xmlsec-1.5.1, when start your application, it loads xmlsec-1.4.3. As result you have class cast exception, when pass DOMReference object between jboss and webapp classloders.
You can resolve your issue in different ways:
remove dependency of org.apache.santuario.xmlsec module in jboss-deployment-structure.xml. Application will use his own defined xmlsec-1.4.3 library
locate dependency xmlsec in pom.xml, set version to 1.5.1, and set scope to provided. Application will use JBoss module with xmlsec-1.5.1
locate dependency xmlsec in pom.xml and exclude it completly, if your code complies without xmlsec dependency. Application will use JBoss module with xmlsec-1.5.1
mvn:dependency:tree command helps here.

Differences between Jboss EAP6 and Weblogic 11 XML responses

I have a problem with a Webservice deployed in JBoss EAP 6.
I have a war file, that war contains a WS, but, that war originally was developed and tested in a Weblogic 11 AS; and everything works fine BUT
my boss said that my war can deploys in other server (JBoss) that he has mounted in other computer.
Everything is normal, but in the response, the date is different, i mean, in Weblogic, it appears like this:
<birthday class="com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl">
<year>1952</year>
<month>4</month>
<day>17</day>
<timezone>-360</timezone>
<hour>0</hour>
<minute>0</minute>
<second>0</second>
<fractionalSecond>0.000</fractionalSecond>
</birthday>
So, in JBoss EAP 6, the date appears whit more fields, like this:
<birthday class="org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl">
<orig__year>1944</orig__year>
<orig__month>3</orig__month>
<orig__day>1</orig__day>
<orig__hour>0</orig__hour>
<orig__minute>0</orig__minute>
<orig__second>0</orig__second>
<orig__fracSeconds>0.000</orig__fracSeconds>
<orig__timezone>-300</orig__timezone>
<year>1944</year>
<month>3</month>
<day>1</day>
<timezone>-300</timezone>
<hour>0</hour>
<minute>0</minute>
<second>0</second>
<fractionalSecond>0.000</fractionalSecond>
</birthday>
My question is, how can i switch the implementation of the de/serializer for this data type?
It seems, Weblogic uses the JDK interal classes to make the job, but JBoss uses it's own implementation.
I read about to add a xml file (jboss-deployment-structure.xml) to the war archive, i integrate one xml, like this:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
<deployment>
<exclusions>
<module name="org.apache.xerces" />
</exclusions>
<dependencies>
<module name="sun.jdk" >
</module>
<system>
<paths>
<path name="com/sun/org/apache/xerces/internal/jaxp/datatype"/>
</paths>
</system>
</dependencies>
</deployment>
</jboss-deployment-structure>
If i understood well, that xml avoids the use of the JBoss XML implementation (xerces) then i can use the internal classes of the JDK; but the result is the same, any ideas?
I resolve my issue in this form:
I change the default xerces implementation, in this path
{JBOSS_HOME}\modules\system\layers\base\org\apache\xerces\main
I add two files: jaxp-api-1.4.5.jar and jaxp-ri-1.4.5.
And in the module.xml i made a change for the jar declared as a resource root, like this:
<module xmlns="urn:jboss:module:1.1" name="org.apache.xerces">
<resources>
<!--<resource-root path="xercesImpl-2.9.1-redhat-4.jar"/> -->
<resource-root path="jaxp-ri-1.4.5.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
Now, my xml comes with the desired XMLGregorianCalendar implementation.
Cheers.

Categories