|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: IDEA配置maven tomcat插件Debug/热部署 |
| 4 | +categories: tools |
| 5 | +tags: idea |
| 6 | +--- |
| 7 | + |
| 8 | +* content |
| 9 | +{:toc} |
| 10 | + |
| 11 | +# 配置maven tomcat插件 |
| 12 | + |
| 13 | +## 集成tomcatX-maven-plugin |
| 14 | + |
| 15 | +```xml |
| 16 | +<plugin> |
| 17 | + <groupId>org.apache.tomcat.maven</groupId> |
| 18 | + <artifactId>tomcat7-maven-plugin</artifactId> |
| 19 | + <!-- or if you want to use tomcat 6.x --> |
| 20 | + <!--<artifactId>tomcat6-maven-plugin</artifactId>--> |
| 21 | + <version>2.2</version> |
| 22 | + <configuration> |
| 23 | + <path>/</path> |
| 24 | + </configuration> |
| 25 | +</plugin> |
| 26 | +``` |
| 27 | + |
| 28 | +现在只需要运行就可以运行项目了 |
| 29 | + |
| 30 | +``` |
| 31 | +mvn clean tomcat7:run |
| 32 | +``` |
| 33 | +> 但是这仅仅是运行项目,在这种情况下不能debug也没有热部署的功能,每次必须进行关闭 **mvn tomcat7:shutdown** |
| 34 | +
|
| 35 | +## Idea Debug配置 |
| 36 | + |
| 37 | +* 添加maven的Run/Debug项(Run->Edit Config) |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +* 填写相应的命令 |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +> 这样只要进行debug启动就可以调试了但是,改完以后idea是不会自动部署的。 |
| 46 | +
|
| 47 | +## Idea 热部署 |
| 48 | + |
| 49 | +> 这种方法是通过tomcat的管理后天进行热部署 |
| 50 | +
|
| 51 | +### 相关的步骤如下 |
| 52 | + |
| 53 | +* 修改tomcat的tomcat-users.xml |
| 54 | +```xml |
| 55 | +<role rolename="admin"/> |
| 56 | +<role rolename="admin-gui"/> |
| 57 | +<role rolename="manager"/> |
| 58 | +<role rolename="manager-script"/> |
| 59 | +<role rolename="manager-gui"/> |
| 60 | +<role rolename="manager-jmx"/> |
| 61 | +<role rolename="manager-status"/> |
| 62 | +<user username="admin" password="admin" roles="admin,manager,manager-gui,admin-gui,manager-script,manager-jmx,manager-status"/> |
| 63 | +``` |
| 64 | +* 修改的pom文件的配置 |
| 65 | + |
| 66 | +```xml |
| 67 | +<plugin> |
| 68 | + <groupId>org.apache.tomcat.maven</groupId> |
| 69 | + <artifactId>tomcat7-maven-plugin</artifactId> |
| 70 | + <!-- or if you want to use tomcat 6.x --> |
| 71 | + <!--<artifactId>tomcat6-maven-plugin</artifactId>--> |
| 72 | + <version>2.2</version> |
| 73 | + <configuration> |
| 74 | + <url>http://localhost:8080/manager/text</url> |
| 75 | + <server>tomcat</server> |
| 76 | + <username>admin</username> |
| 77 | + <password>admin</password> |
| 78 | + <uriEncoding>UTF-8</uriEncoding> |
| 79 | + <path>/</path> |
| 80 | + </configuration> |
| 81 | +</plugin> |
| 82 | +``` |
| 83 | +* 修改maven的setting.xml文件 |
| 84 | + |
| 85 | +编辑**~/.m2/setting.xml** 添加如下内容: |
| 86 | + |
| 87 | +```xml |
| 88 | +<settings> |
| 89 | + <servers> |
| 90 | + <server> |
| 91 | + <id>tomcat</id><!-- 这里的id和pom文件定义的server一致 --> |
| 92 | + <username>admin</username> |
| 93 | + <password>admin</password> |
| 94 | + </server> |
| 95 | + </servers> |
| 96 | +</settings> |
| 97 | +``` |
| 98 | +> 现在可以通过命令行来启动tomcat(**注意:是在外部不是通过mvn tomcat7:run进行启动的,因为这种条件下启动的配置和通过tomcat命令启动是不同的**) |
| 99 | +
|
| 100 | +现在通过**mvn tomcat7:deploy**进行部署就可以了 |
| 101 | + |
| 102 | +最后还是没有实现maven-tomcat插件既能debug又能热部署(又没闲钱使用JReble的服务,只能凑合着了),如果后续有好的方法在更新此文。 |
0 commit comments