简体   繁体   English

如何在Jetty Maven插件中启用CachingWebAppClassLoader?

[英]How to enable CachingWebAppClassLoader in Jetty Maven Plugin?

I'm trying to improve startup performance of a Java web app in development environment. 我正在尝试在开发环境中提高Java Web应用程序的启动性能。 It uses jetty-maven-plugin and mvn jetty:run is used to start the app. 它使用jetty-maven-plugin和mvn jetty:run用于启动应用程序。

I followed instructions at http://www.eclipse.org/jetty/documentation/9.3.x/jetty-classloading.html to register this new CachingWebAppClassLoader . 我按照http://www.eclipse.org/jetty/documentation/9.3.x/jetty-classloading.html上的说明注册了这个新的CachingWebAppClassLoader

<Configure id="mywebapp" class="org.eclipse.jetty.webapp.WebAppContext">

...

  <Set name="classLoader">
    <New class="org.eclipse.jetty.webapp.CachingWebAppClassLoader">
      <Arg><Ref refid="mywebapp"/></Arg>
    </New>
  </Set>

...
</Configure>

However, org.eclipse.jetty.webapp.WebAppClassLoader.* continued to show up in jvisualvm CPU sampler but not the CachingWebAppClassLoader 但是, org.eclipse.jetty.webapp.WebAppClassLoader.*继续显示在jvisualvm CPU采样器中,但不会显示在CachingWebAppClassLoader

I verified that my registration of classloader is at least being discovered by supplying an invalid class name in which case ClassNotFoundException was thrown. 我验证了我的类加载器注册至少是通过提供无效的类名来发现的,在这种情况下引发了ClassNotFoundException I'm guessing my configuration of classloader is being consumed but not being used or something like that. 我猜我的类加载器的配置正在消耗但没有被使用或类似的东西。 Any ideas? 有任何想法吗?

In addition, please let me know if you are aware of any other variants of classloaders that could be used to improve performance. 此外,如果您了解可用于提高性能的任何其他类加载器变体,请告诉我。

jetty-maven-plugin uses a specialized WebAppContext, called JettyWebAppContext : jetty-maven-plugin使用专门的WebAppContext,称为JettyWebAppContext

JettyWebAppContext Extends the WebAppContext to specialize for the maven environment. JettyWebAppContext扩展WebAppContext以专门用于maven环境。

So your WebAppContext binding in jetty.xml is created but is then left unused. 因此,创建了jetty.xml的WebAppContext绑定,但之后未使用。

An obvious workaround would be to set your WebApplicationContext class to org.eclipse.jetty.maven.plugin.JettyWebAppContext in your jetty.xml, but unfortunately this does not work : 一个明显的解决方法是将您的WebApplicationContext类设置为jetty.xml中的org.eclipse.jetty.maven.plugin.JettyWebAppContext ,但不幸的是,这不起作用

You can define your resourcehandler in jetty.xml, however you shouldn't define your webapp in jetty.xml, as the purpose of the jetty maven plugin is to make development easier by automatically deploying your unassembled webapp. 您可以在jetty.xml中定义资源处理程序,但是不应该在jetty.xml中定义您的webapp,因为jetty maven插件的目的是通过自动部署未组装的Web应用程序来简化开发。 So if you take your webapp definition out of jetty.xml things should work. 因此,如果您将您的webapp定义从jetty.xml中删除,那么事情应该可行。

Another possible workaround would have been to set the classLoader property on the default JettyWebAppContext instance in your pom.xml , using webApp configuration element as described here : 另一种可能的解决方法本来设置classLoader的默认属性JettyWebAppContext比如在你pom.xml ,使用webApp配置元素的描述在这里

<webApp>         
    <classLoader>org.eclipse.jetty.webapp.CachingWebAppClassLoader</classLoader>
</webApp>  

Unfortunately that won't work either, as CachingWebAppClassLoader constructor requires a reference to the underlying WebAppClassLoader.Context , so it will fail to be instantiated. 不幸的是,这也不起作用,因为CachingWebAppClassLoader构造函数需要对底层WebAppClassLoader.Context的引用,因此它将无法实例化。

I'm not sure if there is any other workaround for this (maybe using an additional contextHandler will do it), but even if you manage to make it work with a caching classloader, that will probably break the change detection and hot redeploy, which is basically the core idea behind the jetty-maven-plugin : 我不确定是否有任何其他解决方法(可能使用额外的contextHandler会这样做),但即使你设法使它与缓存类加载器一起工作,这可能会破坏变更检测和热重新部署,基本上是jetty-maven-plugin背后的核心思想:

This goal is used in-situ on a Maven project without first requiring that the project is assembled into a war, saving time during the development cycle. 该目标在Maven项目中就地使用,而无需首先要求将项目组装成战争,从而在开发周期中节省时间。

... ...

Once invoked, the plugin can be configured to run continuously, scanning for changes in the project and automatically performing a hot redeploy when necessary. 调用后,插件可以配置为连续运行,扫描项目中的更改并在必要时自动执行热重新部署。 This allows the developer to concentrate on coding changes to the project using their IDE of choice and have those changes immediately and transparently reflected in the running web container, eliminating development time that is wasted on rebuilding, reassembling and redeploying. 这允许开发人员使用他们选择的IDE专注于对项目的更改进行编码,并将这些更改立即透明地反映在正在运行的Web容器中,从而消除了在重建,重新组装和重新部署时浪费的开发时间。

So I'm not sure if that would be a good idea anyway. 所以我不确定这是不是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM