maven+tomcat7配置

来源:互联网 发布:pr软件 编辑:程序博客网 时间:2024/05/22 11:40

maven+tomcat7配置

tomcat7配置

首先打开tomcat安装目录中的conf/tomcat-users.xml,在内部添加如下代码

<role rolename="manager-gui"/>    <role rolename="manager-script"/>    <user username="xxxx" password="xxxxx" roles="manager-gui, manager-script"/>    

maven配置

在maven的安装目录中的conf文件夹中有settings.xml,或者在maven仓库中有settings.xml,打开该xml文件,在内部添加如下代码:

<server> <id>tomcat</id> <username>xxxx</username> <password>xxxx</password></server>

注意

  1. 这里的id可以随便取名,但是注意要与pom.xml文件中的id相同,maven根据这个id找到相应的服务器将项目部署上去。
  2. username为上述tomcat的tomcat-users.xml中新增user的username。
  3. password为上述tomcat的tomcat-user.xml中新增user的password。

项目中pom.xml配置

pom.xml需要增加tomcat-maven-plugin插件,代码如下所示:

 <plugins>              <plugin>                  <groupId>org.apache.tomcat.maven</groupId>                <artifactId>tomcat7-maven-plugin</artifactId>                 <version>2.2</version>                               <configuration>                           <server>tomcat</server>                         <url>http://localhost:8080/manager/text</url>                              </configuration>              </plugin>   </plugins>  

注意:

  1. <server>tomcat</server>中tomcat就是在上述的maven配置中<id>tomcat</id>
  2. <url>........../text</url>注意tomcat7必须以text结尾
  3. maven命令要以tomcat7开头,例如tomcat7:deploy,tomcat7:redeploy
  4. 注意该插件的groupid和artifactid:
 <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> 

将其与老版本的tomcat-maven插件区别开来,即:

<groupId>org.codehaus.mojo</groupId>                <artifactId>tomcat-maven-plugin</artifactId>

新版本的tomcat-maven-plugin支持tomcat6和tomcat7,两者区别如下:

  <groupId>org.apache.tomcat.maven</groupId>    <artifactId>tomcat6-maven-plugin</artifactId>    <groupId>org.apache.tomcat.maven</groupId>    <artifactId>tomcat7-maven-plugin</artifactId>  
0 0
原创粉丝点击