如何在tomcat中部署将在不同端口上运行的多个Web应用程序? [英] How to deploy multiple web application in tomcat which will run on different ports?

查看:282
本文介绍了如何在tomcat中部署将在不同端口上运行的多个Web应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在tomcat中部署将在不同端口上运行的多个Java Web应用程序? -如何进行设置,以便不同的Web应用程序可以在不同的端口上运行 -要做到这一点需要做些什么?

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?

推荐答案

您将需要在server.xml文件(tomcat_home/conf)中设置其他服务.如果您尚未更改服务器文件,则应该已经有一个名为Catalina的文件(我使用的是Tomcat 5.5,根据版本的不同,您可能会有所不同)

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>

请注意,名称已从Catalina更改为Dev2,将localhost更改为MyDev.将这些更改为您认为适合您的应用程序的任何内容.端口和连接器也已更改. 设置新服务后,您需要将应用程序部署到正确的服务/端口.您可以通过使用XML文件(请参见虚拟主机)

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/

Tomcat_Home/conf/Dev2/MyDev/

针对您要设置的各个端口

for the respective ports which you are setting up

这时,您所要做的就是添加更多文件,以将服务"指向您的应用程序. 例如,在Tomcat_Home/conf/Dev2/MyDev/下,我有一个名为Another.xml的文件.该文件包含以下内容

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>

现在我可以使用网址http://127.0.0.1:8090/Another访问新应用程序 如果尝试使用默认端口8080访问此端口,则会收到错误消息,因为未针对该给定端口部署应用程序.

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.

关于此设置的几点注意事项.如果使用VirtualVM查看应用程序,则会注意到它们共享相同的进程ID.因此,您必须格外小心自己的资源.他们将使用相同的堆空间,并且所有线程将显示在同一列表中.如果您已经登录了应用程序(即Log4j),请确保可以选择显示哪个线程正在执行该工作,否则可能很难判断该线程来自哪个端口/应用程序.

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.

正如Bozho所指出的那样,只运行两个Tomcat实例而不是一台服务器侦听多个端口可能更容易.

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.

这篇关于如何在tomcat中部署将在不同端口上运行的多个Web应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆