因为没有深入的去学习Tomcat,所以下面的方法只是简单的解决了这个问题。
第一种方式是:
Eclispse使用的是安装版的Tomcaat,项目直接发布到Tomcat/webapps目录下。
直接去Tomcat中去修改server.xml文件,将文件内容修改为:
<?xml version="1.0" encoding="UTF-8"?><Server port="9005" shutdown="SHUTDOWN"><Listener className="org.apache.catalina.startup.VersionLoggerListener"/><Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/><Listener className="org.apache.catalina.core.JasperListener"/><Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/><Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/><Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/><GlobalNamingResources><Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/></GlobalNamingResources><Service name="Catalina"><Connector connectionTimeout="20000" port="9080" protocol="HTTP/1.1" redirectPort="8443"/><Connector port="9009" protocol="AJP/1.3" redirectPort="8443"/><Engine defaultHost="localhost" name="Catalina"><Realm className="org.apache.catalina.realm.LockOutRealm"><Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/></Realm><Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true"><Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/><Context docBase="livingstudio" path="/livingstudio" reloadable="true" source="org.eclipse.jst.jee.server:livingstudio"/></Host></Engine></Service><Service name="Catalina1"><Connector connectionTimeout="20000" port="9081" protocol="HTTP/1.1" redirectPort="8443"/><Connector port="9009" protocol="AJP/1.3" redirectPort="8443"/><Engine defaultHost="localhost" name="Catalina1"><Realm className="org.apache.catalina.realm.LockOutRealm"><Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/></Realm><Host appBase="webapps2" autoDeploy="true" name="localhost" unpackWARs="true"><Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/><Context docBase="project" path="/project" reloadable="true" source="org.eclipse.jst.jee.server:project"/></Host></Engine></Service></Server>
然后复制一份到Eclipse中,将Server文件夹下的server.xml文件替换成上述文本即可。
在Tomcat文件夹下进行如下操作:复制webapps目录,改名webapps2,然后将发布的项目2复制到webapps2里面即可。
因为Eclispse在发布时会将项目都发布到webapps文件夹下,还需要将项目2删掉。然后再次启动Eclipse才可以。
注意:端口号port的修改,service 名name和Engine 名name的修改,appBase的修改。
第二种方式是:
Eclipse中引用的Tomcat是解压版的,项目发布呢按照默认发布,就是发布在工作空间的目录中。
然后再Eclipse中分别启动两个Tomcat服务器,用来分别发布这两个项目。
然后分别在Server文件夹下的server.xml分别替换成下面的文本即可。
<?xml version="1.0" encoding="UTF-8"?><Server port="8010" shutdown="SHUTDOWN"><Listener className="org.apache.catalina.startup.VersionLoggerListener"/><Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/><Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/><Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/><Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/><GlobalNamingResources><Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/></GlobalNamingResources><Service name="Catalina"><Connector connectionTimeout="20000" port="8011" protocol="HTTP/1.1" redirectPort="8443"/><Connector port="8012" protocol="AJP/1.3" redirectPort="8443"/><Engine defaultHost="localhost" name="Catalina"><Realm className="org.apache.catalina.realm.LockOutRealm"><Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/></Realm><Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true"><Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/><Context docBase="livingstudio" path="/" reloadable="true" source="org.eclipse.jst.jee.server:livingstudio"/></Host></Engine></Service></Server>
和
<?xml version="1.0" encoding="UTF-8"?><Server port="8015" shutdown="SHUTDOWN"><Listener className="org.apache.catalina.startup.VersionLoggerListener"/><Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/><Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/><Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/><Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/><GlobalNamingResources><Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/></GlobalNamingResources><Service name="Catalina2"><Connector connectionTimeout="20000" port="8016" protocol="HTTP/1.1" redirectPort="8443"/><Connector port="8017" protocol="AJP/1.3" redirectPort="8443"/><Engine defaultHost="localhost" name="Catalina2"><Realm className="org.apache.catalina.realm.LockOutRealm"><Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/></Realm><Host appBase="webapps2" autoDeploy="true" name="localhost" unpackWARs="true"><Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/><Context docBase="project" path="/" reloadable="true" source="org.eclipse.jst.jee.server:project"/></Host></Engine></Service></Server>
然后依次启动tomcat即可。
注意:<Server port="8015" shutdown="SHUTDOWN">
段里port的修改。和下面代码行中port 的修改。
推荐使用第二种方法,更方便一点。当然如果有更好的方法欢迎留言讨论。