[maven]maven插件 tomcat7-maven-plugin 的使用


使用 tomcat7-maven-plugin,可以将tomcat内嵌到web项目中,直接运行webapp项目。

第一步、pom.xml的配置:

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.tomcat.mavengroupId>
            <artifactId>tomcat7-maven-pluginartifactId>
            <version>2.2version>

            <configuration>                
                <path>/path> 
                <port>9090port>
                <uriEncoding>UTF-8uriEncoding>
            configuration>
        plugin>

    plugins>
build>

第二步、配置maven的运行参数:

添加Maven,并在Command line中输入:

clean tomcat7:run

点击保存,然后run。

访问http://localhost:9090

tomcat7-maven-plugin 常用命令:

tomcat7:run 启动嵌入式tomcat ,并运行当前项目
tomcat7:deploy  --部署一个web war包
tomcat7:reload  --重新加载web war包
tomcat7:start    --启动tomcat
tomcat7:stop    --停止tomcat
tomcat7:undeploy--停止一个war包

mvn tomcat7:deploy //第一次
mvn tomcat7:redeploy//之后

//这里我要求先重新打包,并跳过测试,再部署

//第一次
mvn package  -Pdevelop -Dmaven.skip.test=true tomcat7:deploy

//之后
mvn package  -Pdevelop -Dmaven.skip.test=true tomcat7:redeploy

拓展:maven的 java 编译插件

<build>
    <plugins>
        
        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-compiler-pluginartifactId>
            <version>3.6.0version>
            <configuration>
                <source>1.8source>  
                <target>1.8target>
                <encoding>UTF-8encoding>
            configuration>
        plugin>
    plugins>
build>

这是我们常用的编译方式,配合tomcat使用。