Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy multiple web application in tomcat which will run on different ports?

Tags:

java

tomcat

How to deploy multiple java web application in tomcat which will run on different ports ? - How to do settings so that different web application will run on different ports - What all needs to be done for achieving this?

like image 973
LetsSyncUp Avatar asked Dec 06 '10 13:12

LetsSyncUp


2 Answers

You will need to setup another service in your server.xml file (tomcat_home/conf). If you havent changed your server file, you should already have one named Catalina (I am using Tomcat 5.5, you may have something slightly different depending on version)

<Service name="Dev2">
    <Connector port="8090" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true" />
    <Connector port="8092" 
               enableLookups="false" redirectPort="9443" protocol="AJP/1.3" />

    <Engine name="Dev2" defaultHost="MyDev">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>
      <Host name="MyDev" appBase="webapps"
       unpackWARs="true" autoDeploy="true"
       xmlValidation="false" xmlNamespaceAware="false">
      </Host>
    </Engine>
</Service>

Notice that the names have changed from Catalina to Dev2, and localhost to MyDev. Change these to whatever you seem fit for your application. The ports and connectors have also changed. Once the new Service is setup, you then need to deploy applications to the proper Service/Port. You accomplish this by using XML files under (See Virtual Hosting )

Tomcat_Home/conf/Catalina/localhost/

and

Tomcat_Home/conf/Dev2/MyDev/

for the respective ports which you are setting up

At this point all you have to do is add a few more files to point the Service to your application. As an Example, under Tomcat_Home/conf/Dev2/MyDev/ I have a file called Another.xml This file contains the following

<Context path="/" docBase="C:/to_delete" debug="10" crossContext="false">
</Context>

Now I can access the new application using the web address http://127.0.0.1:8090/Another If I try and access this using my default port of 8080, I get an error as the application was not deployed for that given port.

Few things to note about this setup. If you use VirtualVM to look at the application, you will notice that they share the same process ID. Therefore you have to be extra careful of your resources. They will be using the same Heap space, and all the threads will be showing in the same list. If you have logging in your applications (i.e Log4j) ensure you have an option to show which thread was doing the work, as it may be tough to tell otherwise which port/application this would be coming from.

As Bozho has already pointed out, It may be easier to simply have two instances of Tomcat running instead of one server listening on multiple ports.

like image 141
Sean Avatar answered Oct 23 '22 14:10

Sean


You'd better have multiple tomcat installations. It would be easier.

I guess you can register multiple <Connector>s in server.xml, and then filter out the contexts, but that's tedious and sounds wrong.

like image 38
Bozho Avatar answered Oct 23 '22 16:10

Bozho