Archive

Archive for September, 2012

How to run multiple Jetty instances on a host with different ports

September 18, 2012 Comments off

My Goal is to run multiple instance of jetty on the different ports in the same machine.

Pre-Requsites :
Java Installation and JAVA_HOME Environment variable.
Now download the jetty server distributable and unzip(untar) to a directory.

First of all we need to know how jetty is getting started and the various inputs/arguments it needs while starting.

for this i have gone through jetty.sh provided with the distributable.

open the jetty.sh and goto line 474(in my distributable).

give echo RUN_CMD variable.This will show you the command formed before jetty start.

mine is like this

“/home/user/installables/jdk1.6.0_22/bin/java -Xmx1024m -Xms1024m -Djetty.home=/opt/jetty-6.1.14 -Djava.io.tmpdir=/tmp -jar /opt/jetty-6.1.14/start.jar /opt/jetty-6.1.14/etc/jetty-logging.xml /opt/jetty-6.1.14/etc/jetty.xml /opt/jetty-6.1.14/etc/jetty-ssl.xml”

now goto the etc folder

create a copy of jetty.xml and jetty-ssl.xml
create a copy of jetty-A.xml and jetty-ssl-A.xml

change the port number in jetty-A.xml to some other port
<Set name=”port”><SystemProperty name=”jetty.port” default=”7010″/></Set>

change the port number in jetty-ssl-A.xml to some other port
<New>
<Set name=”Port”>7444</Set>

Now create a sh file setup.sh

copy the exe command twice with the different arguments.
“$JAVA_HOME/bin/java -Xmx1024m -Xms1024m -Djetty.home=/opt/jetty-6.1.14 -Djava.io.tmpdir=/tmp -jar /opt/jetty-6.1.14/start.jar /opt/jetty-6.1.14/etc/jetty-logging.xml /opt/jetty-6.1.14/etc/jetty.xml /opt/jetty-6.1.14/etc/jetty-ssl.xml”
“$JAVA_HOME/bin/java -Xmx1024m -Xms1024m -Djetty.home=/opt/jetty-6.1.14 -Djava.io.tmpdir=/tmp -jar /opt/jetty-6.1.14/start.jar /opt/jetty-6.1.14/etc/jetty-logging.xml /opt/jetty-6.1.14/etc/jetty-A.xml /opt/jetty-6.1.14/etc/jetty-ssl-A.xml”

and now run the ./sh file.

two jetty instances will launched with corresponding ports.

Enjoy.

Categories: General Tags: