web 项目配置jetty-maven-plugin,提高启动速度

 

1.原文链接:

https://stackoverflow.com/questions/18527439/run-jetty-run-rjr-with-jetty-8-and-servlet-3-0-scanns-all-jar-files-ignoring-w

2.复制副本

Run-Jetty-Run (RJR) with Jetty 8 and Servlet 3.0 scanns all JAR files ignoring WebInfIncludeJarPattern in jetty-web.xml

I'm using Servlet 3.0 without any web.xml just using Spring WebApplicationInitializer. When I start the Webapplication with Run-Jetty-Run in eclipse, the JARScanning takes about 40 seconds since it tries to find HandlesTypes annotations in all jars.

Thus, I tried to set the WebInfIncludeJarPattern in the jetty-web.xml (I also tried jetty-context.xml) and put it in the webapp/WEB-INF folder as described in http://wiki.eclipse.org/Jetty/Howto/Avoid_slow_deployment. I also set metadata-complete="true". The content of the jetty-web.xml file is:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Call name="setAttribute">
      <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
      <Arg>.*/.*foo-api-[^/]\.jar$|./.*bar-[^/]\.jar$|./.*wibble[^/]*\.jar$</Arg>
    </Call>
</Configure>

I'm using Servlet 3.0 without any web.xml just using Spring WebApplicationInitializer. When I start the Webapplication with Run-Jetty-Run in eclipse, the JARScanning takes about 40 seconds since it tries to find HandlesTypes annotations in all jars.

Thus, I tried to set the WebInfIncludeJarPattern in the jetty-web.xml (I also tried jetty-context.xml) and put it in the webapp/WEB-INF folder as described in http://wiki.eclipse.org/Jetty/Howto/Avoid_slow_deployment. I also set metadata-complete="true". The content of the jetty-web.xml file is:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Call name="setAttribute">
      <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
      <Arg>.*/.*foo-api-[^/]\.jar$|./.*bar-[^/]\.jar$|./.*wibble[^/]*\.jar$</Arg>
    </Call>
</Configure>

However, the JarScanner still scans all the JAR files. In the debug output I can see, that the jetty-web.xml file is parsed AFTER all the JARScanning is done:

OUTPUT:

2013-08-30 09:09:52.836:DBUG:oejw.WebAppContext:preConfigure o.e.j.w.WebAppContext{/admin2,[file:/C:/....../src/main/webapp/]} with runjettyrun.webapp.RJRWebInfConfiguration@1cdc4a5
......
2013-08-30 09:09:52.979:DBUG:oejw.WebAppContext:preConfigure o.e.j.w.WebAppContext{/admin2,[file:/C:/..../src/main/webapp/]} with org.eclipse.jetty.webapp.WebXmlConfiguration@136f39e
2013-08-30 09:09:53.076:DBUG:oejw.WebDescriptor:file:/C:/......../src/main/webapp/WEB-INF/web.xml: Calculated metadatacomplete = True with version=3.0
2013-08-30 09:09:53.076:DBUG:oejw.WebAppContext:preConfigure o.e.j.w.WebAppContext{/admin2,[file:/C:/....../src/main/webapp/]} with runjettyrun.webapp.RJRMetaInfoConfiguration@164de63
... <LOTS OF JARSCANNING>
2013-08-30 09:10:36.677:DBUG:oejw.JarScanner:Search of file:/C:/......./httpclient-cache-4.1.2.jar
2013-08-30 09:10:36.710:DBUG:oejw.WebAppContext:configure o.e.j.w.WebAppContext{/.................} with org.eclipse.jetty.webapp.JettyWebXmlConfiguration@803365
2013-08-30 09:10:36.711:DBUG:oejw.JettyWebXmlConfiguration:Configuring web-jetty.xml
2013-08-30 09:10:36.715:DBUG:oejw.JettyWebXmlConfiguration:Configure: file:/C:/......./src/main/webapp/WEB-INF/jetty-web.xml

How can I force RJR to pick up the jetty-web.xml earlier and only scan the files specified in there? Or is there any other way in RJR to specify the JARS to be scanned?

I am using following versions: Eclipse: Kepler Release 4.3 Build id: 20130614-0229 RJR: 1.3.3.201301020723 Jetty: 8.1.8.v20121106

WINDOWS: 64 bit

Thank you

Here is a workaround for speeding up Jetty 8 with Servlet 3.x.

  1. Create a file (jetty.xml)
  2. Open the RJR configuration
  3. Click on "Show advanced options"
  4. Additional Jetty.xml:

The file (jetty.xml) must have these lines:

<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <Get name="handler">
    <Call name="setAttribute">
      <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
      <Arg>.*/mwa-web-.*\.jar$</Arg>
    </Call>
  </Get>
</Configure>

Here, I'm telling Jetty that any file starting with mwa-web-* should be scanned for Servlet 3.x.

 

<webInfIncludeJarPattern>:jetty-8.1.x之后的版本可以使用,可选参数,配置加载到Web应用程序的Classloader(WEB-INF classpath)中的Jar包的路径或匹配模式,符合条件的jar包将会被检测META-INF、资源、tld和类的继承关系

 

https://www.cnblogs.com/gao241/p/3501578.html

 

WebInfIncludeJarPattern

<webapp>

<webInfIncludeJarPattern>./*spring.*\.jar|.*/classes/.*</webInfIncludeJarPattern>

</webapp>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值