tomcat在项目中启动方式
- tomcat原生应用启动
- tomcat插件启动tomcat7-maven-plugin启动
- tomcat嵌入式启动
- tomcat热部署的简单方式
一.原生启动
1.前往tomcat官网去下载相应的包(http://tomcat.apache.org/)
2.将tomcat压缩包解压到目录下,在bin下运行start.sh(linux)启动,start.bat(windows)启动
3.运行shutdown.sh(linux),shutdown.bat(windows)停止
4.在server.xml配置文件,可在host下添加
/**
*path 访问路径
*docBase 需要静态映射的文件夹,目标是将文件夹映射到webapp中
*reloadable 是否热部署
*/
<Context path="" docBase="" reloadable="true" />
二.插件启动(不推荐)
1.首先我们要知道插件启动是十分方便的,但是它也有一个致命的缺点,那就是长时间未被更新,所以并不推荐在项目部署的时候使用,重点推荐在调试的时候使用这种方式
2.下面是一种简单的使用方式,这种方式的需要加载shapshot启动,不能使用maven库中的2.2版本,因为2.2版本中不能设置staticContextPath和statixContextDocbase
3.下面是案例:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.3-SNAPSHOT</version>
<configuration>
<update>true</update>
<path>/</path>
<port>8080</port>
<server>tomcat7</server>
<staticContextPath>/uploads</staticContextPath>
<staticContextDocbase>/data/uploads</staticContextDocbase>
<uriEncoding>UTF-8</uriEncoding>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>