简体   繁体   English

除了 jars 之外,避免在 Jetty 中扫描类路径 class

[英]Avoid classpath class scanning in Jetty in addition to jars

To make Jetty 9.0 stop scanning classes and jars from classpath I did as described by it's docs: first I created a WEB-INF\jetty-web.xlm file on the project with the following:为了使 Jetty 9.0 停止从类路径扫描类和 jars,我按照文档中的描述进行了操作:首先,我在项目上创建了一个 WEB-INF\jetty-web.xlm 文件,其中包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">

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

    <Call name="setAttribute">
        <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
        <Arg>.\A</Arg>
    </Call>

</Configure>

Then on web.xml I specified both <absolute-ordering/> and metadata-complete="true and I run Jetty with -Dorg.eclipse.jetty.webapp.WebInfConfiguration.LEVEL=ALL and -Dorg.eclipse.jetty.annotations.AnnotationParser.LEVEL=DEBUG to confirm that the scanning was really being skipped, and that seems true for WebContext since there as was list of jars selected by the scanners and now only the project war is listed: Then on web.xml I specified both <absolute-ordering/> and metadata-complete="true and I run Jetty with -Dorg.eclipse.jetty.webapp.WebInfConfiguration.LEVEL=ALL and -Dorg.eclipse.jetty.annotations.AnnotationParser.LEVEL=DEBUG以确认扫描确实被跳过了,这对于 WebContext 来说似乎是正确的,因为扫描仪选择了 jars 列表,现在只列出了项目战争:

2021-02-07 21:43:58.971:INFO:oejsh.ContextHandler:Scanner-1: Started o.e.j.w.WebAppContext@6c7c5cac{Payroll,/payroll-groovy-1.0,file:///E:/Projetos/payroll_groovy/target/payroll-groovy-1.0/,AVAILABLE}{E:\Projetos\payroll_groovy\target\payroll-groovy-1.0.war}

However, AnnotationParser shows jar scanning (I don't understand the difference of both logs...):但是, AnnotationParser显示 jar 扫描(我不明白这两个日志的区别......):

2021-02-07 21:43:57.312:DBUG:oeja.AnnotationParser:qtp1595212853-27: Scanning class from jar file:///E:/Programas/jetty/lib/apache-jstl/org.apache.taglibs.taglibs-standard-impl-1.2.5.jar!/org/apache/taglibs/standard/Version.class->org/apache/taglibs/standard/Version.class[0]
2021-02-07 21:43:57.323:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class from jar file:///E:/Programas/jetty/lib/servlet-api-3.1.jar!/javax/servlet/AsyncEvent.class->javax/servlet/AsyncEvent.class[0]
2021-02-07 21:43:57.323:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class from jar file:///E:/Programas/jetty/lib/servlet-api-3.1.jar!/javax/servlet/AsyncListener.class->javax/servlet/AsyncListener.class[0]
2021-02-07 21:43:57.323:DBUG:oeja.AnnotationParser:qtp1595212853-27: Scanning class from jar file:///E:/Programas/jetty/lib/apache-jstl/org.apache.taglibs.taglibs-standard-impl-1.2.5.jar!/org/apache/taglibs/standard/functions/Functions.class->org/apache/taglibs/standard/functions/Functions.class[0]
2021-02-07 21:43:57.323:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class from jar file:///E:/Programas/jetty/lib/servlet-api-3.1.jar!/javax/servlet/DispatcherType.class->javax/servlet/DispatcherType.class[0]
2021-02-07 21:43:57.323:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class from jar file:///E:/Programas/jetty/lib/servlet-api-3.1.jar!/javax/servlet/Filter.class->javax/servlet/Filter.class[0]
2021-02-07 21:43:57.323:DBUG:oeja.AnnotationParser:qtp1595212853-27: Scanning class from jar file:///E:/Programas/jetty/lib/apache-jstl/org.apache.taglibs.taglibs-standard-impl-1.2.5.jar!/org/apache/taglibs/standard/resources/Resources.class->org/apache/taglibs/standard/resources/Resources.class[0]
2021-02-07 21:43:57.324:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class from jar file:///E:/Programas/jetty/lib/servlet-api-3.1.jar!/javax/servlet/FilterChain.class->javax/servlet/FilterChain.class[0]
2021-02-07 21:43:57.324:DBUG:oeja.AnnotationParser:qtp1595212853-27: Not a class: org/apache/taglibs/standard/resources/Resources.properties
2021-02-07 21:43:57.324:DBUG:oeja.AnnotationParser:qtp1595212853-27: Not a class: org/apache/taglibs/standard/resources/Resources_ja.properties
2021-02-07 21:43:57.324:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class from jar file:///E:/Programas/jetty/lib/servlet-api-3.1.jar!/javax/servlet/FilterConfig.class->javax/servlet/FilterConfig.class[0]
2021-02-07 21:43:57.324:DBUG:oeja.AnnotationParser:qtp1595212853-27: Scanning class from jar file:///E:/Programas/jetty/lib/apache-jstl/org.apache.taglibs.taglibs-standard-impl-1.2.5.jar!/org/apache/taglibs/standard/tag/common/core/CatchTag.class->org/apache/taglibs/standard/tag/common/core/CatchTag.class[0]
2021-02-07 21:43:57.324:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class from jar file:///E:/Programas/jetty/lib/servlet-api-3.1.jar!/javax/servlet/FilterRegistration$Dynamic.class->javax/servlet/FilterRegistration$Dynamic.class[0]

.
.
.

and it keeps on until every jar and every class from the project are listed.它一直持续到列出项目中的每个 jar 和每个 class 为止。 If I add this in the jetty-web.xml:如果我在 jetty-web.xml 中添加这个:

<Call name="setAttribute">
    <Arg>org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern</Arg>
    <Arg>.\A</Arg>
</Call>

then the log shows that the jar scanning ceased, but that is not the case for classes from the classpath:然后日志显示 jar 扫描停止,但类路径中的类并非如此:

2021-02-07 21:50:13.730:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class file:///E:/Projetos/payroll_groovy/target/payroll-groovy-1.0/WEB-INF/classes/com/vmc/DynamicClassFactory$_coreLangMethods_closure1.class
2021-02-07 21:50:13.737:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class file:///E:/Projetos/payroll_groovy/target/payroll-groovy-1.0/WEB-INF/classes/com/vmc/DynamicClassFactory$__clinit__closure2.class
2021-02-07 21:50:13.738:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class file:///E:/Projetos/payroll_groovy/target/payroll-groovy-1.0/WEB-INF/classes/com/vmc/DynamicClassFactory$__clinit__closure3.class
2021-02-07 21:50:13.739:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class file:///E:/Projetos/payroll_groovy/target/payroll-groovy-1.0/WEB-INF/classes/com/vmc/DynamicClassFactory.class
2021-02-07 21:50:13.741:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class file:///E:/Projetos/payroll_groovy/target/payroll-groovy-1.0/WEB-INF/classes/com/vmc/objectMemento/Caretaker.class
2021-02-07 21:50:13.742:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class file:///E:/Projetos/payroll_groovy/target/payroll-groovy-1.0/WEB-INF/classes/com/vmc/objectMemento/InMemoryObjectChangeProvider.class
2021-02-07 21:50:13.743:DBUG:oeja.AnnotationParser:qtp1595212853-29: Scanning class file:///E:/Projetos/payroll_groovy/target/payroll-groovy-1.0/WEB-INF/classes/com/vmc/objectMemento/Memento.class

.
.
.

The odd thing is that @WebListener annotated classes from my classpath were not loaded (maybe because of metadata-complete setting?) despite AnnotationParser telling that they were all scanned.奇怪的是,我的类路径中的@WebListener注释类没有加载(可能是因为元数据完整设置?)尽管AnnotationParser告诉它们都已被扫描。 In any case, I would like to avoid all scanning since there will be no @WebListener annotated classes (I put it just for testing) and so there is no sense on spent time scanning them.无论如何,我想避免所有扫描,因为不会有@WebListener注释类(我把它只是为了测试),所以花时间扫描它们是没有意义的。

So how do I stop Jetty 9.0 from scanning classes from my classpath?那么如何阻止 Jetty 9.0 从我的类路径中扫描类呢?

Jetty 9.0?码头 9.0? Make sure you are using Jetty 9.4.x at least.确保您至少使用 Jetty 9.4.x。 The Jetty 9.0 major version is using a pre-release/alpha version of the Servlet 3.1 specs. Jetty 9.0 主要版本使用的是 Servlet 3.1 规范的预发布/alpha 版本。 You want to go from 9.0 to 9.4 (that's a jump of 4 major versions of Jetty within the Servlet 3.1 top level, so be prepared.)您希望将 go 从 9.0 升级到 9.4(这是 Servlet 3.1 顶层中 Jetty 的 4 个主要版本的跳跃,所以要做好准备。)

Reminder, Jetty versioning (as it has been since 1995) is提醒一下,Jetty 版本控制(自 1995 年以来一直如此)是
<servlet_support>.<major_version>.<minor_version>

  • Jetty 9.x means Servlet 3.1, Jetty 9.x 表示 Servlet 3.1,
  • Jetty 10.x means Servlet 4.0 Jetty 10.x 表示 Servlet 4.0
  • Jetty 11.x means Servlet 5.0 Jetty 11.x 表示 Servlet 5.0

The next value is the major version within that servlet support level.下一个值是该 servlet 支持级别内的主要版本。

As for your attempts to use the org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern attribute to limit what is scanned in the WEB-INF/lib , this is the correct attribute to use, but can only exist in the XML deployable files.至于您尝试使用org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern属性来限制在WEB-INF/lib中扫描的内容,这是要使用的正确属性,但只能存在于 XML 可部署文件中。

This is the ${jetty.base}/webapps/<name>.xml location.这是${jetty.base}/webapps/<name>.xml位置。

Your attempted use of WEB-INF/jetty-web.xml is incorrect, as this file is applied after all of the servlet specific behaviors are fully configured.您尝试使用WEB-INF/jetty-web.xml是不正确的,因为在完全配置了所有 servlet 特定行为之后才应用此文件。 (and servlet specific behaviors is what you want to configure) (和 servlet 特定的行为是你想要配置的)

You need to configure this attribute at the very beginning of the deployment process, which means the only place to define it is within the XML deployable.您需要在部署过程的最开始配置此属性,这意味着定义它的唯一位置是在 XML 可部署中。

Based on your logging output of Payroll,/payroll-groovy-1.0,file:///E:/Projetos/payroll_groovy/target/payroll-groovy-1.0/,AVAILABLE}{E:\Projetos\payroll_groovy\target\payroll-groovy-1.0.war the XML would be...根据您的Payroll,/payroll-groovy-1.0,file:///E:/Projetos/payroll_groovy/target/payroll-groovy-1.0/,AVAILABLE}{E:\Projetos\payroll_groovy\target\payroll-groovy-1.0.war XML 将是......

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/Payroll</Set>
  <Set name="war">E:/Projetos/payroll_groovy/target/payroll-groovy-1.0.war</Set>
  <Call name="setAttribute">
    <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
    <Arg>.*/scannable-[^/]*\.jar$</Arg>
  </Call>
</Configure>

That will deploy your war, and only scan jar files in WEB-INF/lib that start with scannable- .这将部署您的战争,并且仅扫描WEB-INF/lib中以 scannable- 开头的scannable-文件。

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

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