Search code examples
deploymentjbossjboss-eap-6

How to deploy 2 applications(same ear) to a single jboss on different ports. Is it even possible?


I use Jboss eap 6.4. I'd like to have those ears deployed simultaneously but on different ports. If I just put 2 ears into deployments I got: DuplicateServiceException: Service /app already registered.


Solution

  • To configure JBoss for App1.war on port 8080 and App2.war on port 8543, you should implement the following steps:

    • First of all, you have to add socket-binding for 8543 (as port 8080 is already defined).

    <socket-binding name="http2" port="8543"/>

    • In web subsystem the following connectors should be declared:

    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" />

    <connector name="http2" protocol="HTTP/1.1" scheme="http" socket-binding="http2" />

    • Additionally, in web subsystem the following two virtual-servers should be declared:

    <virtual-server name="host1" enable-welcome-root="false" default-web-module="App1.war"> <alias name="first.com"/> </virtual-server>

    <virtual-server name="host2" enable-welcome-root="false" default-web-module="App2.war"> <alias name="second.com"/> </virtual-server>

    • Associate the appropriate virtual-server with the respective connector:

    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"> <virtual-server name="host1"/> </connector> <connector name="http2" protocol="HTTP/1.1" scheme="http" socket-binding="http2"> <virtual-server name="host2"/> </connector>

    • The final step is to configure each application with the right jboss-web.xml in WEB-INF:

    - For App1.war <jboss-web> <virtual-host>host1</virtual-host> </jboss-web>

    - For App2.war <jboss-web> <virtual-host>host2</virtual-host> </jboss-web>

    Now each application can be accessed by following the urls:

    For App1.war - http://first.com:8080/App1/index.jsp

    For App2.war - http://second.com:8543/App2/index.jsp

    Please bear in mind that in /etc/hosts of the system, you must add the corresponding virtual-server alias names:

    127.0.0.1 localhost.localdomain localhost first.com second.com