maven插件jetty的使用

在使用了很长时间的Tomcat之后,我慢慢的喜欢上了jetty,要说原因的话,那就是轻量级,对于初学者很友好,你不需要管那么多的Tomcat下载,你只需要去在pox文件中添加几行代码,就完全可以实现这一切

代码如下(pom.xml):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <packaging>war</packaging>
    <groupId>cn.test.www</groupId>
    <artifactId>testContent</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.3.7.v20160115</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <httpConnector>
                        <port>8080</port>
                    </httpConnector>
                    <webAppConfig>
                        <contextPath>/test</contextPath>
                    </webAppConfig>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

只需要在pom文件中把<build></build>添加就完成了,

*一些参数的定义:

<scanIntervalSeconds>10</scanIntervalSeconds>    大于0就是热部署,修改代码以后不用重新启动
<port>8080</port>      项目的端口号
<webAppConfig>/test</webAppConfig>   这是项目的开头路径,不建议添加    

例如你的项目启动了以后:你要通过 localhost:8080/test 才能访问到系统的欢迎文件(index)

热部署的操作快捷键:
idea中:
  • Ctrl+Shift+F9,编译
  • Ctrl+F9,生成项目
 
 
 
原文地址:https://www.cnblogs.com/Anxc/p/jetty.html