How to Deploy jPOS in JBOSS EAP-7.+
Containers... if you don't get the joke, maybe you're lost! Photo by frank mckenna on Unsplash

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.

No alt text provided for this image
  1. First, we create a directory and name it JPOS_JBOSS.
  2. 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.)
  3. Third, inside jpos_ear_folder create a new folder and name it META-INF.
  4. 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>

  1. 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.)
  2. 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.
No alt text provided for this image

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>
  1. 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();

}
  1. 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.

Harrison Muhari

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

Juma George Odhiambo

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

要查看或添加评论,请登录

Kari?ki K.的更多文章

  • Machine Vision: Making a Face Recognition Android App

    Machine Vision: Making a Face Recognition Android App

    This is the third article in an ongoing series on face recognition. In this article, I shall outline the process of…

  • Machine Vision: Making a Face Recognition Back-end

    Machine Vision: Making a Face Recognition Back-end

    In my previous article, I promised to write a more technical series of articles that chronicle the journey of creating…

  • Machine Vision: First Face Recognition App

    Machine Vision: First Face Recognition App

    On 18th March 2019, a senior colleague invited all coders in our organization to contribute to ongoing internal…

    3 条评论
  • The Making of a Data Scientist: How I Became One

    The Making of a Data Scientist: How I Became One

    At the end of last year I decided I was going to become a machine learning expert. Before that I had created this…

    8 条评论
  • Why You Must Think Out of The Box

    Why You Must Think Out of The Box

    Running a business is a lot like having some examination questions and then coming up with a set of multiple choice…

  • I Hereby Declare myself an iOS Developer

    I Hereby Declare myself an iOS Developer

    I have loved to code since I printed my first “Hello World!” on a cheap, second hand Dell Latitude D160 using C. I have…

    10 条评论
  • To be a Better Leader, Be a Rock

    To be a Better Leader, Be a Rock

    I do not know where these thoughts come from sometimes. So the other day I am riding on a boda-boda headed home from a…

社区洞察

其他会员也浏览了