maven 插件jetty/tomcat启动 web 应用

tomcat

            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                   <configuration>
                      <path>/</path>
                      <port>8000</port>
                      <uriEncoding>UTF-8</uriEncoding>  
                      <server>tomcat7</server>
                   </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>run</goal>
                            </goals>
                        </execution>
                    </executions>
            </plugin>

启动方法:mvn tomcat7:run

jetty

    
  <!-- 这个不能用,不能访问 -->
  <plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.4.5.v20170502</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <httpConnector> <port>80</port> </httpConnector> <webAppConfig> <contextPath>/</contextPath> </webAppConfig> </configuration> </plugin> </plugins>
<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>8.1.16.v20140903</version>
    <configuration>
        <scanIntervalSeconds>10</scanIntervalSeconds>
        <connectors>
            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                <port>7777</port>
            </connector>
        </connectors>
        <webAppConfig>
            <contextPath>/</contextPath>
        </webAppConfig>
    </configuration>
</plugin>

scanIntervalSeconds元素表示该插件扫描项目变更的时间间隔,这里配置为10秒。默认为0,表示不扫描,这样就失去了自动化热部署的功能。
connector 元素用来指定运行的端口号,属性 implementation 不可以删除,值是固定的。默认端口是8080。
启动方法:mvn jetty:run -Djetty.port=9999
启动后,可以在IDE中修改jsp、htmo、css、js甚至java类,只要不是修改类名、方法名等较大的操作,插件都能够扫描变更并更新到web容器中

原文地址:https://www.cnblogs.com/Mike_Chang/p/9383475.html