How to Deploy jPOS in JBOSS EAP-7.+
Recently, a production environment I am responsible for started failing with very weird errors. Everything pointed to an architectural problem and/or JBoss misconfiguration or misuse. Anyway, what quickly came up is that we needed to redesign the architecture and implement it in-place without any major downtimes. We had a number of standalone modules using the jPOS library which needed to be deployed within JBoss as managed deployments. Well, turns out the task of deploying jPOS in JBoss EAP-7 is so scantly documented. Actually, half-way through reading one of the few online references which addressed the topic, I realized that it was addressing EAP-3 and was written 15 years ago!
Anyway, with the help of this article and this StackOverflow post, I was able to finally deploy jPOS as an EAR file that can be run and managed by JBoss. The process is pretty straight-forward, just a few commands and you should have Q2 up and running within JBoss in no time. Below is the folder structure of an EAR file that we are trying to recreate -- this will be the final structure of the jpos_ear_folder mentioned below. We are going to address each red box separately.
- First, we create a directory and name it JPOS_JBOSS.
- Second, inside JPOS_JBOSS create a new directory named jpos_ear_folder. (You can choose any other name as long as you remember to substitute that everywhere. But I would advise you first use the names used in this article until you understand everything that is happening.)
- Third, inside jpos_ear_folder create a new folder and name it META-INF.
- Inside META-INF create two files: jboss-app.xml and application.xml. Copy-paste the code snippets below into these two files as indicated:
<?xml version="1.0" encoding="UTF-8" ?> <jboss-app> <loader-repository>myapp:archive=jposQ.ear</loader-repository> <module> <service>q2mbean-1.0.sar</service> </module> </jboss-app>
application.xml:
<?xml version="1.0" encoding="UTF-8" ?> <application xmlns="https://www.dhirubhai.net/redir/general-malware-page?url=http%3A%2F%2Fjava%2esun%2ecom%2Fxml%2Fns%2Fj2ee" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.dhirubhai.net/redir/general-malware-page?url=http%3A%2F%2Fjava%2esun%2ecom%2Fxml%2Fns%2Fj2ee https://www.dhirubhai.net/redir/general-malware-page?url=http%3A%2F%2Fjava%2esun%2ecom%2Fxml%2Fns%2Fj2ee%2Fapplication_1_4%2exsd" version="1.4"> <display-name>JPOS-in-JBOSS</display-name> <module> <java>jpos.jar</java> </module> </application>
- There we have defined the structure of the EAR file. And we have stated that it uses the jPOS library by declaring a module “jpos.jar” in the application.xml file. Therefore, the next logical step is to copy jPOS jar library and all its dependencies into the root folder of your EAR, i.e. go back inside jpos_ear_folder. (I renamed “jpos.x.x.jar” to jpos.jar because my laziness would not allow me to keep typing “jpos.2.0.2.jar” when I was trying to get this to work.)
- You will notice that in boss-app.xml we have referenced q2mbean-1.0.sar which we have not yet defined. To define this, create another folder in JPOS_JBOSS and name it q2mbean, this folder will have two Java classes and a META-INF folder containing one file: jboss-service.xml.
7. Copy-paste the code snippet below into ../JPOS_JBOSS/q2mbean/META-INF/jboss-service.xml:
<?xml version="1.0" encoding="UTF-8" ?> <server xmlns="urn:jboss:service:7.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd"> <mbean code="org.jpos.mbean.Q2Service" name="Q2:name=Q2Service"> </mbean> </server>
- We shall also need ../JPOS_JBOSS/q2mbean/Q2ServiceMBean.java with the below content:
// Q2ServiceMBean.java package org.jpos.mbean; public interface Q2ServiceMBean{ public void startService(); }
- And, finally, create ../JPOS_JBOSS/q2mbean/Q2Service.java which implements the above interface:
// Q2Service.java package org.jpos.mbean; import org.jpos.q2.Q2; public class Q2Service implements Q2ServiceMBean { private Q2 q2Server; private String pathToDeployFolder = “/path/to/deploy/folder”; public Q2Service() { System.out.println("\n\n\t Q2Service is activated...inside Q2Service() constructor"); q2Server = null; } public void startService() { System.out.println("Q2Service starting >>>>>>>>"); } public void start() { System.out.println("nntStarting start() Q2Service invoked"); Q2 q2 = new Q2(pathToDeployFolder); q2.start(); } public void stop() { q2Server.shutdown(); System.out.println("\n\n\tStopping stop() MyServerMonitor invoked"); } }
Now here is the fun stuff, we finally get to run some commands. If you do not have Java installed, you must be lost! I wonder what you are looking for this far in the wilderness. To create the EAR file itself, we need to archive everything. Basically, think of an EAR file as a zip file with a “.ear” extension. So, in a terminal (or command prompt), cd into the JPOS_JBOSS folder and run the following commands in sequence:
$ cd q2mbean $ javac -cp ../jpos_ear_folder/jpos.jar -d . *.jar $ cd .. $ jar -cf q2mbean-1.0.sar -C q2mbean . $ mv q2mbean-1.0.sar jpos_ear_folder $ jar -cf jposQ.ear -C jpos_ear_folder . $ ls -lrt
You should see the file jposQ.ear listed in the output of the final command above. You can copy the file jposQ.ear to your ../EAP-7.x.x/standalone/deployments folder and it shall be automatically deployed by JBoss.
Team Lead at Eclectics Intl.
5 年Good stuff. I was looking for a way to do this and stumbled upon jreactive (https://github.com/kpavlov/jreactive-8583). You just saved me a few hours of research hehe
System Development Manager at Watu Credit | Leading EV Initiatives
5 年My laziness couldn't allow me to read your article word for word but the setup process works