首先启动tomcat,然后在tomcat的tomcat-users.xml配置文件里写入:
<role rolename="tomcat"/> <role rolename="manager-gui"/> <role rolename="manager-script"/> <user username="tomcat" password="tomcat" roles="tomcat, manager-gui, manager-script"/>
然后在mvn的settings.xml里写入:
<server> <id>tomcat</id> <username>tomcat</username> <password>tomcat</password> </server>
在pom.xml文件添加:
<!-- Run the JUnit unit tests in an isolated classloader --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.4.2</version> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.3</version> <configuration> <webXml>src/main/webapp/WEB-INF/web.xml</webXml> </configuration> </plugin> <!-- generate java doc --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>2.9.1</version> <configuration> <javadocDirectory>target/javadoc</javadocDirectory> <reportOutputDirectory>target/javadoc</reportOutputDirectory> <charset>UTF-8</charset> <encoding>UTF-8</encoding> <docencoding>UTF-8</docencoding> <show>private</show> </configuration> </plugin> <!-- 部署至本机 --> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <url>http://localhost:8080/manager/text</url> <server>tomcat</server> <path>/myWeb</path> <username>tomcat</username> <password>tomcat</password> </configuration> </plugin>
<path>后面的路径不能和项目名称一样,否则报错
且必须添加:
<!-- 导入Java EE jar 包 --> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>7.0</version> <scope>provided</scope> </dependency>
不添加,则报错
下面是常用的命令:
命令 |
描述 |
tomcat7:deploy -X |
部署的时候看详细信息 |
tomcat7:deploy |
部署一个web war包 |
tomcat7:redeploy |
持续部署web项目(推荐使用) |
tomcat7:reload |
重新加载web war包 |
tomcat7:start |
启动tomcat |
tomcat7:stop |
停止tomcat |
tomcat7:undeploy |
停止一个war包 |
tomcat7:run |
启动嵌入式tomcat ,并运行当前项目 |
如果在Windows系统下,redeploy过程无法删除旧项目的目录
必须修改$TOMCAT_HOME/conf/context.xml:
<Context antiJARLocking="true" antiResourceLocking="true">
时间: 2024-11-13 14:27:36