aspose file tools*
The moose likes Tomcat and the fly likes How to run two war files under different port in tomcat6? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to run two war files under different port in tomcat6?" Watch "How to run two war files under different port in tomcat6?" New topic
Author

How to run two war files under different port in tomcat6?

S. Sule
Greenhorn

Joined: Jan 05, 2011
Posts: 13
Hi

I have two war files under webapps folder.
How to access these war files under different port on Tomcat6?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

I don't think it's possible. The port is the server attribute and not the webapp attribute.
Moving to the Tomcat forums


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42291
    
  64
I agree, I don't think it's possible if the war files are in the same directory. But it's easily possible if you keep them in different directories: In your server.xml you need to declare two Service elements, each with an HTTP Connector on a different port, and each with a Host pointing to the two different directories where the war files reside. The Tomcat docs have all the details, but even just studying the server.xml file should make things clearer.


Ping & DNS - my free Android networking tools app
S. Sule
Greenhorn

Joined: Jan 05, 2011
Posts: 13
ok..So you mean to say at a time only one web application can be run under tomcat6 server. .. Is there any way where i can access both my web application under single tomcat6 server.
S. Sule
Greenhorn

Joined: Jan 05, 2011
Posts: 13
Thanks Ulf for the Suggestion

i have also tried that way, i have created two different folder containing different war under webapps, and changed the Server.xml but its not working. Can you please help me into making the changes in the following original Server.xml

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16145
    
  21

We had a long discussion on this several months back. I recommend searching this forum for that thread.

Allowing for my fuzzy memory, however, Tomcat assembles its modules in roughly the following architecture:


A Service "owns" the ports. Each Service defines for its own use a unique set of ports to listen to for HTTP, HTTPS, Tomcat Control and Proxy Tunnelling (for example, Apache-to-Tomcat). These ports are defined in server.xml as Connector elements within the Service element. The OS (no matter which OS) does not permit a given port number to be owned by more than one application, which is why the port set must be unique.

A Host defines a virtual host. You can have more than one if you like. The default one is "localhost". All Hosts within a Service share the same collection of ports.

I may be wrong on this, but I think that TOMCAT_HOME/webapps as a default location for deployed WARs is actually defined by the Host configuration element in server.xml and not hard-wired into Tomcat. Regardless, it's the Service that determines what ports will supply a given Host, and thus a given webapp.

A Context defines a single webapp (WAR). Tomcat has ways of constructing Contexts by default rules if you don't provide one, but all deployed webapps have a Context.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42291
    
  64
S. Sule wrote:i have also tried that way, i have created two different folder containing different war under webapps, and changed the Server.xml but its not working. Can you please help me into making the changes in the following original Server.xml

I don't see where you think you have two HTTP Connector elements, or two Service elements, or where you tried to define two different directories. It looks pretty much like the standard server.xml file that comes with Tomcat.

Please reread my previous post, and also the Tomcat documentation I pointed you to.
S. Sule
Greenhorn

Joined: Jan 05, 2011
Posts: 13
Hi Guys

Please see below my modified Server.xml. I have created two folders PMO and RFPT for my respective war files under webapps folder. still im not able to access these war files on 8080 and 8080 server. Please suggest me the solution after going through server.xml.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42291
    
  64
That looks basically correct, but you may want to give the Host.name and and Engine.defaultHost attributes distinct values (currently they're the same for both).

If something isn't set up right then you should find error messages (or at least starting points for investigation) in the catalina.out log file.

As an aside, using a port below 1024 (like 443) doesn't generally work - the usual approach is to use 8443 or something like that.
S. Sule
Greenhorn

Joined: Jan 05, 2011
Posts: 13
Hi

I have done the neccessary changes highlighted in green color:

<?xml version='1.0' encoding='utf-8'?>

<Server port="8005" shutdown="SHUTDOWN">

<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">
<Connector port="8000" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
keystoreFile="${catalina.base}/conf/.keystore" keystorePass="xxxxx"
clientAuth="false" sslProtocol="TLS" />

<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>

<Host name="localhost" appBase="webapps/PMO"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<Context path="" docBase="Apple"/>
</Host>
</Engine></Service>

<Service name="Catalina2">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />

<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
keystoreFile="${catalina.base}/conf/.keystore" keystorePass="xxxxx"
clientAuth="false" sslProtocol="TLS" />

<Engine name="Catalina2" defaultHost="localhostnew">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>

<Host name="localhostnew" appBase="webapps/RFPT"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
</Engine>
</Service>


</Server>



still it is giving me following error

java.io.FileNotFoundException: C:\IDE\data_RFP\RFPT_Tracker\apache-tomcat-6.0.18\conf\.keystore (The system cannot find the file specified)

what does it mean? can you help with this
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42291
    
  64
Well, does the file exist? In your setup of port 8443 you're telling Tomcat that that's where the keystore is located; if it is located anywhere else, then you need to use the proper path.
S. Sule
Greenhorn

Joined: Jan 05, 2011
Posts: 13

Thanks everyone for your suggestions.
I managed to deploy my 2 project war files on same tomcat6 server through Tomcat Manager
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to run two war files under different port in tomcat6?