转载:http://blog.163.com/xueling1231989@126/blog/static/1026408072013101311395492/
怎么说呢?使用 Jetty Plugin 的时候最爽的是不用你敲打包、部署,然后再启动服务器的指令,只需敲一句:mvn jetty:run
或直接点 eclipse 上的 run 按钮就完事了。而且更爽的是,你修改资源文件,Jetty 能自动扫描到并及时给予反馈进行重加载,
这对修改java文件很有帮助,不用每次修改java文件都要重启服务器,省掉了不少没必要浪费的时间。
当然,如果想要 Jetty 跑得更理想,还需要禁止 Jetty 使用映射缓存。
环境:



项目结构:

pom.xml




























index.jsp






选中项目,右键选择 Run As --> Maven build
Name:根据需要,自己取个名
Goals:输入要执行的 maven 命令
其余的不用管,直接点击 Run

Jetty 运行完成之后,访问:http://localhost:8080/jetty-plugin-demo/

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
禁止 Jetty 使用映射缓存:
当你想试图去修改正在被访问的资源文件,像 CSS、JS、FTL等,这时候你修改完成想保存的时候,是保存不了的。
你必须停掉 Jetty 容器(如果是在CMD下运行的 Jetty 容器,按 Ctrl + C 停掉 Jetty),才能保存。保存完成后必须
重新启动 Jetty 容器才能看见效果。这样做无论是对修改 .css、.js、.ftl 等都非常麻烦和不爽。
究其原因,这是 Jetty 使用了内存映射文件来缓存静态文件。在Windows下面,使用内存映射文件会导致文件被锁定。
解决方案是不使用内存映射文件来做缓存。步骤如下:
根据所使用 Jetty 版本在本地的 maven 仓库中找到 Jetty 版本对应的jar包。
如:
<plugins>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
</plugin>
</plugins>
则需找到( 我的本地的 maven 仓库是在 D:RepositoriesMaven ):
D:RepositoriesMavenorgmortbayjettyjetty6.1.10jetty-6.1.10.jar
用解压缩工具打开此jar包,进到:
jetty-6.1.10.jarorgmortbayjettywebapp
找到webdefault.xml文件,即: jetty-6.1.10.jarorgmortbayjettywebappwebdefault.xml
解压出此文件webdefault.xml,找到:
<param-name>useFileMappedBuffer</param-name>
<param-value>true</param-value>
将 true 改成 false,以禁止使用映射缓存。
删除原jar包中的webdefault.xml文件,将修改过的webdefault.xml文件压缩进去,OK。搞定。
这样之后就能在 Jetty 运行时修改并保存资源文件。
http://www.blogjava.net/fancydeepin/archive/2012/06/23/maven-jetty-plugin.html