> 其它学习 > Maven >

maven的三种部署方式

1.打war包到tomcat/webapps目录
 
 
 
在工程的target目录下会生成war包,将其拷贝到tomcat的webapps目录下即可。
 
 
 
2.使用tomcat-maven插件,在pom.xml的</dependencies>之后添加以下代码,并做相应修改
 <build>
     <finalName>guoguo-maven-web</finalName>
     <plugins>
       <plugin>
           <!-- 3个可用插件 -->
         <groupId>org.apache.tomcat.maven</groupId>
         <artifactId>tomcat6-maven-plugin</artifactId>                    <!-- 命令为tomcat6:redeploy -->
         <!-- <groupId>org.apache.tomcat.maven</groupId> -->
         <!-- <artifactId>tomcat7-maven-plugin</artifactId> -->    <!-- 命令为tomcat7:redeploy -->
         <!-- <groupId>org.codehaus.mojo</groupId> -->
         <!-- <artifactId>tomcat-maven-plugin</artifactId> -->        <!-- 命令为tomcat:redeploy -->
         <!-- <version>2.2</version> -->
       <configuration>
           <!-- <url>http://localhost:8080/manager</url> -->            <!-- tomcat6部署管理路径 -->
           <url>http://localhost:8080/manager/text</url>                <!-- tomcat7部署管理路径 -->
           <username>admin</username>                                <!-- tomcat的管理员账号 -->
           <password>admin</password>
           <port>8080</port>
           <path>/testMaven</path>                            <!-- 部署路径,可以配置为"/",此时相当于webapps/Root,访问的url无需输入项目名 -->
           <charset>UTF-8</charset>
           <encoding>UTF-8</encoding>
           <!-- 运行redeploy命令前,要能正常访问http://localhost:8080/manager-->
       </configuration>
       </plugin>
   </plugins>
  </build>
 
运行redeploy命令前,要启动tomcat,并能正常访问http://localhost:8080/manageName
 
通过项目右键 run as --> maven build... --> main --> goals 中填入 tomcat:redeploy命令即可部署成功,这样部署有时会使tomcat出错,出错需要重启tomcat
 
 
 
3.直接使用servers部署
首先确保编译配置正常
 
 
 
配置好之后,通过右键servers中tomcat,add and remove...添加项目,重启tomcat即可
 
第一种我已经不用了,第二种适合直接部署到测试服务器,第三种适合本地的调试。
 
 
 
附录:
 
tomcat管理员配置,在servers项目的tomcat-users.xml中添加如下配置,如果你是直接使用bin/startup.bat启动tomcat,则修改conf/tomcat-users.xml
 
----------tomcat6管理员配置----------
<role rolename="manager"/>
<user username="admin" password="admin" roles="manager"/>
----------tomcat6管理员配置----------
 
----------tomcat7管理员配置----------
<role rolename="manager-script" />
<role rolename="manager-gui"/>
<user username="admin" password="admin" roles="manager-gui,manager-script"/>
 


 

(责任编辑:IT)