5、maven+jetty本地创建开发环境

注意这里使用的是jetty7.0以上的版本

在项目的pom.xml添加内容:

1、pom.xml添加依赖

<!-- Jetty -->
<dependency>
   <groupId>org.eclipse.jetty.aggregate</groupId>
   <artifactId>jetty-all</artifactId>
   <version>8.0.4.v20111024</version>
</dependency>  
  
<!-- Jetty Webapp -->
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-webapp</artifactId>
    <version>8.0.4.v20111024</version>
</dependency>


wKiom1Rge_mRVcO-AAG1r9Osdj4028.jpg


2、pom.xml添加插件

<!-- jetty插件 -->
<plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>8.1.16.v20140903</version>
    <configuration>
        <scanIntervalSeconds>5</scanIntervalSeconds>
        <connectors>  
            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">  
                <port>8080</port>  
            </connector>  
        </connectors>   
        <webAppConfig>
            <contextPath>/${finalName}</contextPath>
            <defaultsDescriptor>src/main/resources/webdefault.xml</defaultsDescriptor>
        </webAppConfig>
    </configuration>
</plugin>

解决jetty运行时锁定文件的步骤:

1、在jetty包下找到etc文件夹里面找到webdefault.xml文件,把文件里的useFileMappedBuffer参数,把值设成false。

2、把修改过的webdefault.xml文件,放在项目的src/main/resources/文件夹下

嫌麻烦的可以直接下载  http://pan.baidu.com/s/1c0ALAeO ,webdefault.xml文件,已经修改好的


jetty的默认端口号:8080,mvn_xfg_cp_client发布后访问的项目名,<defaultsDescriptor>src/main/resources/webdefault.xml</defaultsDescriptor>目的在于jetty运行时解决锁定文件。

原因是Jetty会使用内存映射文件来缓存静态文件,其中包括js、css文件。在Windows下面,使用内存映射文件会导致文件被锁定。解决方案是不使用内存映射文件来做缓存。


右键所在项目运行的模块:Run  As -> Run Configurations

wKioL1RggGmTTjvHAAMm2XMeV5k638.jpg

Goals:填入

clean  install  jetty:run


浏览器访问:localhost:8080/mvn_xfg_cp_client



本文出自 “江山如画待赢归” 博客,谢绝转载!

你可能感兴趣的:(maven,jetty)