从lib目录加载jar文件的顺序 [英] Order of loading jar files from lib directory

查看:1379
本文介绍了从lib目录加载jar文件的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释一下从Tomcat中的lib目录加载jar文件的顺序吗?
是按字母顺序排列的吗?随机?或者其他一些订单?

Could anyone explain the order in which jar files are loaded from the lib directory within Tomcat? Is it alphabetical? Random? Or some other order?

推荐答案

这一切都在 Tomcat的ClassLoading HOW-TO 。它不一定按字母顺序排列。如果您发现了这种行为,那么如果您打算让Web应用程序在服务器之间移植,则应该绝对不。例如,Tomcat 6巧合地命令它,但Tomcat 8没有。

It's all described in Tomcat's ClassLoading HOW-TO. It's not necessarily in alphabetic order. If you observed that behaviour, it should absolutely not be relied upon if you intend to keep your webapp portable across servers. For example, Tomcat 6 "coincidentally" orders it, but Tomcat 8 does not.

总结,加载顺序如下:


  1. bootstrap / system( JRE / lib ,然后 server.loader

  2. webapp库( WEB-INF / classes ,然后 WEB-INF / lib

  3. 公共库( common.loader ,然后 Tomcat / lib

  4. webapp-shared libraries( shared.loader

  1. bootstrap/system (JRE/lib, then server.loader)
  2. webapp libraries (WEB-INF/classes, then WEB-INF/lib)
  3. common libraries (common.loader, then Tomcat/lib)
  4. webapp-shared libraries (shared.loader)

如果您想保证在 JAR Y之后加载JAR X,那么您需要将JAR X放在其中一个出现的位置稍后在上面的清单中。

If you would like to guarantee that JAR X is loaded after JAR Y, then you'd need to put JAR X in one of the places which appears later in the listing above.

然而,有一些例外情况,在 tomcat docs

There are exceptions however, which are mentioned in the tomcat docs


最后,Web应用程序类加载器将始终首先委派给JavaEE API Tomcat实现的规范类(Servlet,JSP,EL,WebSocket)。 Tomcat中的所有其他类加载器都遵循通常的委托模式。

Lastly, the web application class loader will always delegate first for JavaEE API classes for the specifications implemented by Tomcat (Servlet, JSP, EL, WebSocket). All other class loaders in Tomcat follow the usual delegation pattern.

这意味着如果webapp包含任何JavaEE类( javax。* ),然后它将被tomcat忽略。

That means if a webapp contains any JavaEE classes (javax.*), then it will be ignored by tomcat.

对于每个加载器,这些类只是由JVM在无论何时需要导入/执行并且尚未加载它们。

For each loader, the classes are just loaded by the JVM in the order whenever they needs to be imported/executed and are not loaded yet.

这篇关于从lib目录加载jar文件的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆