tomcat用户及相关权限的配置
在tomcat安装路径下找到conf/tomcat-users.xml配置文件,添加manager权限的用户,具体配置如下:
<tomcat-users>
<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="tomcat" password="tomcat"
roles="manager-gui,manager-script,manager-jmx,manager-status,admin-script,admin-gui"/>
</tomcat-users>
Maven的server配置
在Maven的安装路径找到conf目录下的settings.xml文件,如图所示:
在servers节点中添加tomcat7下配置的用户信息(id可以任意填写,但username和password必须和步骤1一致),具体配置如下:
<!--注意:这里的用户名和密码必须与上诉中配置的用户名和密码一致-->
<servers>
<server>
<id>tomcat7</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
pom.xml文件中的配置
<build>
<finalName>mojie-api-web-x3zl</finalName>
<plugins>
<!-- 指定编译jdk为1.7 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<target>1.7</target>
<resource>1.7</resource>
</configuration>
</plugin>
<!-- tomcat7插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8080</port>
<url>http://localhost:8080/mojie-api-web-x3zl/text</url>
<server>tomcat7</server>
<username>tomcat</username>
<password>tomcat</password>
<uriEncoding>UTF-8</uriEncoding>
<path>/v1/web/appliance</path>
<contextReloadable>true</contextReloadable>
</configuration>
</plugin>
</plugins>
</build>
注意必须输入的是tomcat7 因为是根据pom.xml配置中server中的id名称而来。
以上配置好之后,可以配置启动tomcat命令,如下图所示:
也可以不用配置tomcat:run命令,直接通过展开maven projects的方式启动,具体步骤如下:
maven集成tomcat插件常见命令如下:
- tomcat7:deploy 部署一个web war包
- tomcat7:reload 重新加载web war包
- tomcat7:start 启动tomcat
- tomcat7:stop 停止tomcat
- tomcat7:undeploy 停止一个war包
- tomcat7:run 启动嵌入式tomcat ,并运行当前项目