首页 > 代码库 > tomcat使用指南(二)-修改端口

tomcat使用指南(二)-修改端口

当要启动两个tomcat,或者8080端口已被其他程序占用时,就需要修改tomcat的默认端口。

修改server.xml,首先把8080端口改为8081:
    <Connector port="8080" protocol="HTTP/1.1" 
               connectionTimeout="20000" 
               redirectPort="8443" />

此时启动,会报错:
SEVERE: Failed to initialize end point associated with ProtocolHandler ["ajp-bio-8009"]
Throwable occurred: java.net.BindException: The socket name is already in use. <null>:8009
修改server.xml,首先把8009端口改为8010:
    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

此时启动,会报错:
SEVERE: StandardServer.await: create[localhost:8005]: 
Throwable occurred: java.net.BindException: The socket name is already in use.
修改server.xml,首先把8005端口改为8006:
<Server port="8005" shutdown="SHUTDOWN">

注意:如果在unix下拷贝长xml配置,会自动换行,比如报错:
Throwable occurred: org.xml.sax.SAXParseException: Attribute name "cr" associated with an element type "Context" must be followed by the ‘ = ‘ character.
是因为<Context path="" docBase="F:\code\trunk\mapp\thfund\web\thfund\web" debug="5" reloadable="true" crossContext="true">
到crossContext这里,cr就换行了,下一行是ossContext。

本文出处:
http://blog.csdn.net/ouyida3
201.2.2

tomcat使用指南(二)-修改端口