Deploy multiple war files in JBoss to different port

In this post, we will see how to deploy multiple war files to the different port using a single JBoss EAP server.

Introduction.

First, we will create two separate projects with the name module1 and module2. Both modules will contain a separate war file.

There is no dependency on both modules. Once we will have two wars we will deploy into JBoss on a different port. We are going to use JBoss 7 (JBoss-EAP-7.1.0) for this tutorial. We need to put both the war file in the deployment folder and run the standalone.bat file.

First, we will create a war file using maven with name module1.war and module1.war then we will deploy this war file to JBoss server. For changing the name of war file we need to add <finalName>${project.artifactId}</finalName> in pom.xml(no need to worry we will have in pom.xml).

After deployment, we will able to hit two separate URI (port will be different) using a single JBoss. This is what we are going to do.

http://localhost:8099/module1/book1

Deploy multiple war files in JBoss to different port

http://localhost:7099/module2/book2

Deploy multiple war files in JBoss to different port

 

Deploy multiple war files in JBoss to different port example from scratch.

Open eclipse and create maven project, Don’t forget to check ‘Create a simple project (skip)’click on next. Fill all details(GroupId – module1, ArtifactId – module1 and name – module1) and click on finish. Keep packaging as the war.

 

Step 4 – Modify the pom.xml.

Modify this one where you have installed JDK

When we modify pom.xml and save it, Maven will download all jar needed.

Create a WEB-INF folder inside webapp and inside WEB-INF create an xml file with name jboss.web.xml

Deploy multiple war files in JBoss to different port

Deploy multiple war files in JBoss to different port

 

Create package module1 and define all files controller class(BookController.java), Book.java and SpringMainModule1.java in this package. We will keep this application simple. Our main purpose is to build(create war) and deploy the application on JBoss 7.

Our directory structure looks as below.

Deploy multiple war files in JBoss to different port

 

Initially, we will have nothing in our target folder since I have had already given the build, I have module1.war in the target folder.

Let’s define three class.

Book.java

BookController.java

SpringMainModule1.java

Jboss-web.xml for module1. Just create for now we will see later why we are doing.

 

We are good now, let’s create a war file using mvn clean install. We will go till below directory and run mvn clean install.

 

 

 

 

Now go to the target folder, we should have module1.war. We are good now we have module1.war. Let’s create module2.war the same. Just follow the same steps as earlier discussed. Our directory structure will look as below.

 

 

Let’s do some modification in classes.

Book.java will be same only package name will differ.

BookController.java

SpringMainModule2.java

Jboss-web.xml for module2

 

 

Let’s build this module separately the same way as we build module1.

Now we have module2.war in the target folder and yes we have now module1.war and module2.war.

Our directory structure looks as below after module1 and module2.

Let’s download JBoss 7(jboss-eap-7.1.0) and extract it.

Deploy multiple war files in JBoss to different port

Copy both the war file and paste into the deployment folder.

Deploy multiple war files in JBoss to different port

Go to configuration folder(jboss-eap-7.1.0\jboss-eap-7.1\standalone\configuration), open standalone.xml file and define the new port and create a virtual server. We are not going to use default one i.e 8080 instead of that we will define two separate port i.e 8099 for module1 deployment and 7099 for module2. Following modification needed in standalone.xml.

Define new ports – 

<socket-binding name=”config-manager1″ port=”8099″/>
<socket-binding name=”config-manager2″ port=”7099″/>

Define virtual server in subsystem urn:jboss:domain:undertow- 

<server name=”config-server1″>
<http-listener name=”config-listener1″ socket-binding=”config-manager1″/>
<host name=”host1″ alias=”localhost” default-web-module = “module1″>
</host>
</server>

<server name=”config-server2″>
<http-listener name=”config-listener2″ socket-binding=”config-manager2″/>
<host name=”host2″ alias=”localhost” default-web-module = “module2”>
</host>
</server>

After changes our standalone.xml should looks as below.
<server>

………………….

<subsystem xmlns=”urn:jboss:domain:undertow:4.0″>
<buffer-cache name=”default”/>
<server name=”default-server”>
<http-listener name=”default” socket-binding=”http” redirect-socket=”https” enable-http2=”true”/>
<https-listener name=”https” socket-binding=”https” security-realm=”ApplicationRealm” enable-http2=”true”/>
<host name=”default-host” alias=”localhost”>
<location name=”/” handler=”welcome-content”/>
<filter-ref name=”server-header”/>
<filter-ref name=”x-powered-by-header”/>
<http-invoker security-realm=”ApplicationRealm”/>
</host>
</server>
<server name=”config-server1″>
<http-listener name=”config-listener1″ socket-binding=”config-manager1″/>
<host name=”host1″ alias=”localhost” default-web-module = “module1”>
</host>
</server>

<server name=”config-server2″>
<http-listener name=”config-listener2″ socket-binding=”config-manager2″/>
<host name=”host2″ alias=”localhost” default-web-module = “module2”>
</host>
</server>

<servlet-container name=”default”>
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name=”welcome-content” path=”${jboss.home.dir}/welcome-content”/>
</handlers>
<filters>
<response-header name=”server-header” header-name=”Server” header-value=”JBoss-EAP/7″/>
<response-header name=”x-powered-by-header” header-name=”X-Powered-By” header-value=”Undertow/1″/>
</filters>
</subsystem>
<subsystem xmlns=”urn:jboss:domain:webservices:2.0″>
<wsdl-host>${jboss.bind.address:127.0.0.1}</wsdl-host>
<endpoint-config name=”Standard-Endpoint-Config”/>
<endpoint-config name=”Recording-Endpoint-Config”>
<pre-handler-chain name=”recording-handlers” protocol-bindings=”##SOAP11_HTTP ##SOAP11_HTTP_MTOM ##SOAP12_HTTP ##SOAP12_HTTP_MTOM”>
<handler name=”RecordingHandler” class=”org.jboss.ws.common.invocation.RecordingServerHandler”/>
</pre-handler-chain>
</endpoint-config>
<client-config name=”Standard-Client-Config”/>
</subsystem>
<subsystem xmlns=”urn:jboss:domain:weld:4.0″/>
</profile>
<interfaces>
<interface name=”management”>
<inet-address value=”${jboss.bind.address.management:127.0.0.1}”/>
</interface>
<interface name=”public”>
<inet-address value=”${jboss.bind.address:127.0.0.1}”/>
</interface>
</interfaces>
<socket-binding-group name=”standard-sockets” default-interface=”public” port-offset=”${jboss.socket.binding.port-offset:0}”>
<socket-binding name=”management-http” interface=”management” port=”${jboss.management.http.port:9990}”/>
<socket-binding name=”management-https” interface=”management” port=”${jboss.management.https.port:9993}”/>
<socket-binding name=”ajp” port=”${jboss.ajp.port:8009}”/>
<socket-binding name=”http” port=”${jboss.http.port:1988}”/>
<socket-binding name=”https” port=”${jboss.https.port:8443}”/>
<socket-binding name=”txn-recovery-environment” port=”4712″/>
<socket-binding name=”txn-status-manager” port=”4713″/>
<socket-binding name=”config-manager1″ port=”8099″/>
<socket-binding name=”config-manager2″ port=”7099″/>
<outbound-socket-binding name=”mail-smtp”>
<remote-destination host=”localhost” port=”25″/>
</outbound-socket-binding>
</socket-binding-group>
</server>

 

Now we need to define these configurations in jboss-web.xml which we have already done. For better understanding once again let’s have a look into jboss-web.xml .

jboss-web.xml for module1.

jboss-web.xml for module2.

 

Testing of the example.

We are good now we can deploy both war files.

Go to the bin folder and run standalone.bat.

Deploy multiple war files in JBoss to different port

Deploy multiple war files in JBoss to different port

Let’s have a look into log file.

Deploy multiple war files in JBoss to different port

Our server is up and both module1.war and module2.war have been deployed.

In the controller we have defined some rest API, we are going to test using postman.

module1.war has been deployed in 8099.

module2.war has been deployed in 7099.

Deploy multiple war files in JBoss to different port

 

That’s all about How to Deploy multiple war files in JBoss to a different port. If you feel any problem just leave a comment.

You may like.

JBoss deployment docs.

Top