maven默认是使用tomcat6跑项目的,这段是让maven用tomcat7/8去跑
在pom.xml中添加
tomcat7
<build>
<!-- we dont want the version to be part of the generated war file name -->
<finalName>${project.artifactId}</finalName>
<defaultGoal>compile</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<!--使用tomcat7运行-->
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<!--运行端口-->
<port>8082</port>
<!--<path>/mgr</path> -->
<uriEncoding>UTF-8</uriEncoding>
<finalName>mgr</finalName>
<!--项目名-->
<path>/KBase</path>
<server>tomcat7</server>
</configuration>
//如果需要发布到容器,需要下面配置
<url>http://10.98.20.80:8080/manager/text</url>
<username>admin</username>
<password>admin</password>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
运行:tomcat7:run
发布:tomcat7:redeploy
tomcat8
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat8-maven-plugin</artifactId>
<version>3.0-r1655215</version>
<configuration>
<port>8080</port>
<uriEncoding>UTF-8</uriEncoding>
<finalName>mgr</finalName>
<!--项目名 -->
<path>/xxxxx</path>
<server>tomcat</server>
//如果需要发布到容器,需要下面配置
<url>http://10.98.20.80:8080/manager/text</url>
<username>admin</username>
<password>admin</password>
</configuration>
</plugin>
运行:tomcat8:run
发布:tomcat8:redeploy
发布的配置
配置tomcat的conf/tomcat-users.xml 中配置一个user
<role rolename="admin-gui"/>
<role rolename="admin-script"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="123456" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
tomcat8除了上一步,还需要配置webapps/manager/META-INF/context.xml,允许其他IP访问
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="^.*$" />
</Context>