Maven Jetty插件使用
本机环境
JDK8 Maven 3.5 Jetty 9.3 Eclipse Mars
pom.xml配置
在你的 pom.xml 文件中添加 jetty 插件的描述信息
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.v20160115</version>
</plugin>
</plugins>
</build>
启动 & 停止
命令行方式启动 jetty mvn jetty:run ,可以通过 Ctrl + C 停止 jetty 服务。
或者,在 eclipse 中选中项目 --> 右键 --> Run As --> Maven build...,在 Goals 栏输入 jetty:run (与命令行方式相比,仅仅是少了 mvn 前缀,为方便起见,以下均以命令行方式介绍。)
jetty 9 部署的项目的 Context path 默认是 /,也就是说,项目的访问入口地址是:http://localhost:8080(不带项目名),
如果你希望通过命令 mvn jetty:stop 执行关闭 jetty 服务,你需要像下面一样在你的 pom.xml 配置文件中添加一个特殊的端口和控制键:
<configuration>
[...]
<stopKey>shutdown</stopKey>
<stopPort>9966</stopPort>
[...]
</configuration>
你仍可以通过 mvn jetty:run 启动 jetty 服务,可以通过 mvn jetty:stop 来停止 jetty 服务。
端口配置
jetty 默认使用的端口是 8080,命令行的方式修改端口的命令是: mvn -Djetty.port=8081 jetty:run 。pom.xml 配置方式如下:
<configuration>
[...]
<httpConnector>
<port>8081</port>
</httpConnector>
[...]
</configuration>
自动热部署
在你的 pom.xml 中添加如下配置:
<configuration>
[...]
<scanIntervalSeconds>2</scanIntervalSeconds>
[...]
</configuration>
默认值是 0。大于 0 的数值表示开启,0 表示关闭,单位为秒。以配置数值为一个周期,自动的扫描文件检查其内容是否有变化,如果发现文件的
内容被改变,则自动重新部署运用。命令行的方式: mvn -Djetty.scanIntervalSeconds=2 jetty:run 。
手动重加载
在你的 pom.xml 文件中添加如下配置,reload 的可选值 :[automatic|manual]
<configuration>
[...]
<reload>manual</reload>
[...]
</configuration>
默认值为 automatic,它与大于 0 的 scanIntervalSeconds 节点一起作用,实现自动热部署的工作。设为 manual 的好处是,当你改变文件
内容并保存时,不会马上触发自动扫描和重部署的动作,你还可以继续的修改,直至你在 Console 或命令行中敲回车键(Enter)的时候才触发重
新加载的动作。这样可以更加的方便调试修改。命令行的方式是: mvn -Djetty.reload=manual jetty:run 。
访问日志
在你的 pom.xml 文件添加如下配置:
<configuration>
[...]
<requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
<filename>target/access-yyyy_mm_dd.log</filename>
<filenameDateFormat>yyyy_MM_dd</filenameDateFormat>
<logDateFormat>yyyy-MM-dd HH:mm:ss</logDateFormat>
<logTimeZone>GMT+8:00</logTimeZone>
<append>true</append>
<logServer>true</logServer>
<retainDays>120</retainDays>
<logCookies>true</logCookies>
</requestLog>
[...]
</configuration>
org.eclipse.jetty.server.NCSARequestLog 是 org.eclipse.jetty.server.RequestLog 的一个实现类。
org.eclipse.jetty.server.NCSARequestLog 是一种伪标准的 NCSA 日志格式。下面是一些节点参数的解释:
filename:日志文件的名称
filenameDateFormat:日志文件的名称的日期格式,它要求日志文件名必须含有 yyyy_mm_dd 串
logDateFormat:日志内容的时间格式
logTimeZone:时区
append:追加到日志
logServer:记录访问的主机名
retainDays:日志文件保存的天数, 超过删除
logCookies:记录 cookies
启动 jetty 服务,在项目的 target 目录下会生成一个 access-2015_06_23.log 文件,该文件中的其中一条记录如下:
localhost 0:0:0:0:0:0:0:1 - - [2015-06-23 01:17:05] "GET /css/main.css HTTP/1.1" 304 -
"http://localhost:8081/" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/35.0.1916.153 Safari/537.36 SE 2.X MetaSr 1.0" "JSESSIONID=2gyikovul2iz168116l2afo4f"
转储快照
在你的 pom.xml 文件添加如下配置:
<configuration>
[...]
<dumpOnStart>true</dumpOnStart>
[...]
</configuration>
dumpOnStart 默认值为 false,如果设为 true,jetty 在启动时会把当前服务进程的内存信息输出到控制台中,但这并不会保存到文件中。
WEB上下文
最常用的是 contextPath,它的配置如下:
<configuration>
[...]
<webApp>
<contextPath>/${project.artifactId}</contextPath>
</webApp>
[...]
</configuration>
contextPath 的默认值的 /,${project.artifactId} 引用了 <artifactId> 节点的值,即项目的名称。
项目的静态资源文件目录默认是 src/main/webapp,如果静态资源目录有多个,或者不在默认的 src/main/webapp 目录下,可做如下配置:
<configuration>
[...]
<webApp>
<contextPath>/${project.artifactId}</contextPath>
<resourceBases>
<resourceBase>${project.basedir}/src/main/webapp</resourceBase>
<resourceBase>${project.basedir}/commons</resourceBase>
</resourceBases>
</webApp>
[...]
</configuration>
引用静态资源文件时,路径不包含资源目录的名称,如 commons/main.css,引用方式为:<link href="main.css" rel="stylesheet" />
更多参数信息可参考 jetty-maven-plugin.html#configuring-your-webapp
完整的配置
附 pom.xml 文件中 jetty 插件的完整配置片段:
<build>
[...]
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.v20160115</version>
<configuration>
<httpConnector>
<port>8081</port>
</httpConnector>
<stopKey>shutdown</stopKey>
<stopPort>9966</stopPort>
<!--
<scanIntervalSeconds>2</scanIntervalSeconds>
-->
<reload>manual</reload>
<dumpOnStart>true</dumpOnStart>
<webApp>
<contextPath>/${project.artifactId}</contextPath>
<!--
<resourceBases>
<resourceBase>${project.basedir}/src/main/webapp</resourceBase>
<resourceBase>${project.basedir}/commons</resourceBase>
</resourceBases>
-->
</webApp>
<requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
<filename>target/access-yyyy_mm_dd.log</filename>
<filenameDateFormat>yyyy_MM_dd</filenameDateFormat>
<logDateFormat>yyyy-MM-dd HH:mm:ss</logDateFormat>
<logTimeZone>GMT+8:00</logTimeZone>
<append>true</append>
<logServer>true</logServer>
<retainDays>120</retainDays>
<logCookies>true</logCookies>
</requestLog>
</configuration>
</plugin>
</plugins>
[...]
</build>
更多有关 jetty 的配置信息可参考 http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html
参考:http://www.blogjava.net/fancydeepin/archive/2015/06/23/maven-jetty-plugin.html
Maven Jetty插件使用的更多相关文章
- 【转】Maven Jetty 插件的问题(css/js等目录死锁)的解决
Maven Jetty 插件的问题(css/js等目录死锁,不能自动刷新)的解决: 1. 打开下面的目录:C:\Users\用户名\.m2\repository\org\eclipse\jetty ...
- 转 maven jetty 插件
maven jetty 插件使用 本机环境 JDK 7 Maven 3.2 Jetty 9.2 Eclipse Luna pom.xml 配置 在你的 pom.xml 文件中添加 jetty 插件的描 ...
- idea maven jetty插件热部署
maven tomcat插件好像无法进行热部署,jetty可以如下配置实现热部署,但是idea无法进行自动编译,所以需要如下快捷键 Ctrl+Shift+F9,编译 Ctrl+F9,生成项目 < ...
- maven jetty 插件 允许修改 js
<!--允许修改js,css--> <servlet> <servlet-name>default</servlet-name> <init-pa ...
- maven jetty struts异常 There is no Action mapped for namespace [/] and action name [] associated with context path
毕业设计中用maven jetty插件调试时,struts出现这个错误,直接http://localhost:8080 无法进入默认主页,但换tomcat就没问题,最后在这篇文章找到答案 http:/ ...
- eclipse运行maven的jetty插件内存溢出
系统运行在Maven中的Jetty插件下,当在Eclipse运行clean jetty:run时,系统提示OutOfMemoryError: PermGen space.解决办法:设置run as - ...
- 在eclipse中使用jetty插件替代m2e开发调试maven web项目
第一步在相应的web项目上配置jetty插件,配置如下: <plugin> <groupId>org.mortbay.jetty</groupId> <art ...
- maven中jetty插件配置
maven中jetty插件的配置,可用于项目在内置jetty服务器中的部署. <plugin> <groupId>org.mortbay.jetty</groupId&g ...
- IDEA热部署(二)---jetty插件启动maven项目
jetty插件的配置 我们使用jetty插件来进行启动我们的maven项目,在pom.xml中进行配置: <plugins> <plugin> <groupId>o ...
随机推荐
- C#对Windows服务组的启动与停止
Windows服务大家都不陌生,Windows服务组的概念,貌似MS并没有这个说法. 作为一名软件开发者,我们的机器上安装有各种开发工具,伴随着各种相关服务. Visual Studio可以不打开,S ...
- Inter网关做Team的方法
1.到Inter官网上找到相关驱动程序 2.在安装过程中,要求勾选高级网络 3.驱动安装完成后,打开网卡的属性窗口,在“分组”选项卡中,勾中,并输入Team名称 4.选择需要做Team的网卡 5.选择 ...
- PAT 1029. Median
尼玛,数组偶数个数的时候取中位数是取中间两者中的前者,还tmd一直再算平均,卧槽 #include <iostream> #include <cstdio> #include ...
- luogu P3065 first——trie树相关
题目描述 Bessie has been playing with strings again. She found that by changing the order of the alphabe ...
- 军事机密(Secret.pas)
军事机密(Secret.pas) [问题描述] 军方截获的信息由n(n<=30000)个数字组成,因为是敌国的高端秘密,所以一时不能破获.最原始的想法就是对这n个数进行小到大排序, ...
- Visual Studio Code插件
Material Theme 下载量:130 万 Visual Studio Code 最悠久的主题! Auto Import 下载量:46 万 自动去查找.分析.然后提供代码补全.对于 TypeSc ...
- MAVLink Onboard Integration Tutorial
MAVLink Onboard Integration Tutorial MAVLink is a header-only library, which means that you don't ha ...
- 毕向东_Java基础视频教程第21天_IO流(1)
第21天-01-IO流(对象的序列化) ObjectInputStream与ObjectOutputStream 被操作的对象需要实现Serializable接口(标记接口) 非必须, 但强烈建议所有 ...
- 用java实现从命令行接收多个数字,求和之后输出结果。
用java实现从命令行接收多个数字,求和之后输出结果. 1 设计思想: (1)建立类. (2)输出参数个数. (3)定义int型的num和sum,分别用来存储参数和参数的和. (4)用for循环讲参数 ...
- vue从安装到初始化项目