使用Maven + Jetty时,如何不锁定js css 静态资源

转自:http://www.cnblogs.com/shihujiang/archive/2013/08/21/3272641.html

Jetty版本的问题,Jetty8按原文操作会有问题,注意红色字体的部分。

Jetty会使用内存映射文件来缓存静态文件,包括js,css文件。

在Windows下,使用内存映射文件会导致文件被锁定,所以当Jetty启动的时候无法在编辑器对js或者css文件进行编辑。

解决办法是更改Jetty默认配置,不适用内存映射文件来做缓存。

解决步骤如下:

1. 找到webdefault.xml, 在你用的那个jetty-server-XXX.jar中,webdefault.xml文件在包org\mortbay\jetty\webapp下。

把webdefault.xml拷贝一个副本到项目中,在副本进行修改,并使用副本的配置,而不是去更改jar包里面的文件。

2. 修改useFileMappedBuffer参数的值为false

3.在pom.xml中指定使用修改过的webdefault.xml

<plugins>
            <plugin>
                 <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> 
                    <version>8.1.16.v20140903</version> 
                    <configuration> 
                        <webAppSourceDirectory>${basedir}/WebContent</webAppSourceDirectory>
                        <contextXml>${project.basedir}/resources/jetty-context.xml</contextXml>
                         <connectors> 
                            <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector"> 
                                <port>9090</port>
                            </connector> 
                        </connectors> 
                        <webAppConfig>
                            <contextPath>/test</contextPath>
                            <defaultsDescriptor>${basedir}/resources/webdefault.xml</defaultsDescriptor>
                        </webAppConfig>
                    </configuration> 
  </plugin>
</plugins>


第二种方法是修改项目中的 WEB-INF/web.xml 文件,在其中加入这个节点。总觉得这个方法不是很好,不推荐。
<servlet>
<!– Override init parameter to avoid nasty –>
<!– file locking issue on windows.         –>
<servlet-name>default</servlet-name>
<init-param>
<param-name>useFileMappedBuffer</param-name>
<param-value>false</param-value>
</init-param>
</servlet>

【转】maven的jetty插件提示No Transaction manager found导致启动慢的解决方法

转自:http://blog.csdn.net/chaijunkun/article/details/37923905
在 使用maven开发web项目极大地方便了jar包的依赖,在测试时也可以集成Servlet容器,从启动速度和量级上看,Jetty无疑是不二选择,然 而从8.x开始,如果你的web项目中不包含数据库访问(或者说没有事务管理器)的话,在其启动时会提示找不到事务管理器,输出信息如下

oejpw.PlusConfiguration:No Transaction manager found – if your webapp requires one, please configure one.
而且启动过程会暂停十几秒,在反复调试代码时很浪费时间,经过多天在网上搜索资料,终于找到了解决办法。
首先是pom.xml中关于插件的配置:

<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.15.v20140411</version>
<configuration>
<stopKey>stop</stopKey>
<stopPort>9999</stopPort>
<scanIntervalSeconds>1</scanIntervalSeconds>
<contextXml>${project.basedir}/src/main/resources/jetty-context.xml</contextXml>
<webApp>
<contextPath>/</contextPath>
</webApp>
<connectors>
<connector implementation=”org.eclipse.jetty.server.nio.SelectChannelConnector”>
<port>80</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>

重要的是加上<contextXml>配 置,我们要对jetty的服务器属性进行配置。本例中把配置文件放到了/src/main/resources中(如果你不希望打包时带上这个文件,可以 放到/src/test/resources中,改下配置即可),文件名为:jetty-context.xml。接下来是配置文件:
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE Configure PUBLIC “-//Mort Bay Consulting//DTD Configure//EN” “http://www.eclipse.org/jetty/configure.dtd”>
<Configure class=”org.eclipse.jetty.webapp.WebAppContext”>
<Call name=”setAttribute”>
<Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
<Arg>.*/.*jsp-api-[^/]\.jar$|./.*jsp-[^/]\.jar$|./.*taglibs[^/]*\.jar$</Arg>
</Call>
</Configure>
亲测可用。