要想在一个工作空间启动多个工程,而它们使用的是同一个tomcat,就需要修改为不同的启动端口,修改方法:
修改pom.xml中的端口部分:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<name>Apache Tomcat v6.0</name>
<url>http://localhost/MSPortal</url>
<server>tomcat6</server>
<username>admin</username>
<password>admin</password>
<path>/MSPortal</path>
<port>8081</port>
</configuration>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat6-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<name>Apache Tomcat v6.0</name>
<url>http://localhost/MSPortal</url>
<server>tomcat6</server>
<username>admin</username>
<password>admin</password>
<path>/MSPortal</path>
<port>8081</port>
</configuration>
……
</plugin>
其中<server>tomcat6</server>需要在
c:\users\shalom\.m2\settings.xml中配置,如下:
<servers>
<server>
<id>tomcat6</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
<id>tomcat6</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
username和password配置在tomcat的安装目录下的
/conf/tomcat-users.xml中,如下配置:
<tomcat-users>
<user username="admin" password="admin" roles="manager"/>
</tomcat-users>
</tomcat-users>
意思是给admin用户配置管理员权限。
这些配好之后,启动配置中的Goals如果写的是clean tomcat:run,会使用eclipse自带的tomcat,使用默认8080端口,使上面的配置不生效,如果出现这种情况,就把参数中的tomcat改为
tomcat6,这个名字要对应server中的id,这样就可以生效了。
由于是不同端口启动的不同工程,在工程之间交互时往往使用相对地址,同一个前缀无法适应多端口,这时候要借助
nginx,在proxy_pass中配置不同端口,用域名方式访问工程即可。注意nginx不能放在中文路径下,不然会报错:[emerg] 5664#8528: CreateFile() "E:\软件\nginx-1.7.8/conf/nginx.conf" failed (1113: No mapping for the Unicode character exists in the target multi-byte code page)