Google Analytics

Search

To search for specific articles you can use advanced Google features. Go to www.google.com and enter "site:darrellgrainger.blogspot.com" before your search terms, e.g.

site:darrellgrainger.blogspot.com CSS selectors

will search for "CSS selectors" but only on my site.


Thursday, February 18, 2010

Changing ports in JBoss

If you are running JBoss and find some of the ports it requires (and it requires a few) are in use or if you wish to run multiple copies of JBoss, there is a quick and easy way to change the ports.

There are three sets of ports defined for JBoss. They are referred to as 'ports-default', 'ports-01' and 'ports-02'. The ports-default are the ones we all know and love, e.g. 8080 for the HTTP, 1098 for RMI, etc. The ports-01 are the same numbers but add 100. So the HTTP port becomes 8180, 1198 for RMI, etc. The ports-02 are the same numbers but add 200 to the default ports. So HTTP becomes 8280, 1298 for RMI, etc.

If you go to the JBOSS_HOME (the directory you unzipped the JBoss files into) you will find a server/ directory. In the server/ directory is usually an all/, default/ and minimal/ directory. This works for all of them but lets look at the default/ directory. In the default/ directory is a conf/ directory. So the directory we are looking in would be $JBOSS_HOME/server/default/conf/ (or %JBOSS_HOME%\server\default\conf\ on Windows).

In this directory is a jboss-service.xml file. Open this file, with a text editor, and search for Service Binding. When you find it you will see something like:
<!-- ==================================================================== -->
   <!-- Service Binding                                                      -->
   <!-- ==================================================================== -->

   <!-- Automatically activated when generatting the clustering environment -->
   <!-- @TESTSUITE_CLUSTER_CONFIG@ -->

   <!--
      | Binding service manager for port/host mapping. This is a sample
      | config that demonstrates a JBoss instances with a server name 'ports-01'
      | loading its bindings from an XML file using the ServicesStoreFactory
      | implementation returned by the XMLServicesStoreFactory.
      |
      | ServerName: The unique name assigned to a JBoss server instance for
      | lookup purposes. This allows a single ServicesStore to handle mulitiple
      | JBoss servers.
      |
      | StoreURL: The URL string passed to org.jboss.services.binding.ServicesStore
      | during initialization that specifies how to connect to the bindings store.
      | StoreFactory: The org.jboss.services.binding.ServicesStoreFactory interface
      | implementation to create to obtain the ServicesStore instance.

   <mbean code="org.jboss.services.binding.ServiceBindingManager"
     name="jboss.system:service=ServiceBindingManager">
     <attribute name="ServerName">ports-01</attribute>
     <attribute name="StoreURL">${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml</attribute>
     <attribute name="StoreFactoryClassName">
       org.jboss.services.binding.XMLServicesStoreFactory
     </attribute>
   </mbean>
   -->

You will notice at the bottom is -->. This means the <mbean> tag is inside a comment block. If you move the --> to above the start of the <mbean> tag, so you have:
<!-- ==================================================================== -->
   <!-- Service Binding                                                      -->
   <!-- ==================================================================== -->

   <!-- Automatically activated when generatting the clustering environment -->
   <!-- @TESTSUITE_CLUSTER_CONFIG@ -->

   <!--
      | Binding service manager for port/host mapping. This is a sample
      | config that demonstrates a JBoss instances with a server name 'ports-01'
      | loading its bindings from an XML file using the ServicesStoreFactory
      | implementation returned by the XMLServicesStoreFactory.
      |
      | ServerName: The unique name assigned to a JBoss server instance for
      | lookup purposes. This allows a single ServicesStore to handle mulitiple
      | JBoss servers.
      |
      | StoreURL: The URL string passed to org.jboss.services.binding.ServicesStore
      | during initialization that specifies how to connect to the bindings store.
      | StoreFactory: The org.jboss.services.binding.ServicesStoreFactory interface
      | implementation to create to obtain the ServicesStore instance.
   -->

   <mbean code="org.jboss.services.binding.ServiceBindingManager"
     name="jboss.system:service=ServiceBindingManager">
     <attribute name="ServerName">ports-01</attribute>
     <attribute name="StoreURL">${jboss.home.url}/docs/examples/binding-manager/sample-bindings.xml</attribute>
     <attribute name="StoreFactoryClassName">
       org.jboss.services.binding.XMLServicesStoreFactory
     </attribute>
   </mbean>

The <mbean> will no longer be commented out. Notice the ports-01 in the <mbean>. This will cause JBoss to start up with the different ports. You can also change this to ports-02 and run a third copy of JBoss. Good if you want to create a cluster.

Personally, I copy the default/ directory and save it as 01/ and another copy as 02/. I then edit the jboss-service.xml in 01/ to use ports-01 and the jboss-service.xml in 02/ to use ports-02. So now I have default, 01 and 02 to match with ports-default, ports-01 and ports-02.

No comments: