Tomcat 8类加载 - [WEB-INF / lib]和[tomcat / lib]中的JAR之间的区别 [英] Tomcat 8 classloading - difference between JAR in [WEB-INF/lib] and [tomcat/lib]
问题描述
这里说普通的类加载器是所有Web应用程序都可见。那么在我的 war
应用程序的 WEB-INF / lib
文件夹中有一个JAR文件和有什么区别Tomcat的 lib
文件夹中的相同JAR文件?
It says here that the common classloader is visible to all web application. So what is the difference between having a JAR file within the WEB-INF/lib
folder of my war
application and having the same JAR file within Tomcat's lib
folder?
此JAR是我创建的Java SPI的提供程序。当我把它放在 WEB-INF / lib
下时,一切都很完美。但是,如果我尝试将此JAR置于Tomcat的 lib
文件夹下(或在 shared / lib
之后将其配置为 catalina.properties
)我收到错误。第二个选项对我来说更好,因为我需要完全解耦我的应用程序和提供程序。
This JAR is a provider for a Java SPI that I created. When I have it under WEB-INF/lib
, everything works perfectly. But if I try to put this JAR under Tomcat's lib
folder (or under shared/lib
after configuring it in catalina.properties
) I get errors. The second option is better for me because I need total decoupling of my application and the provider.
我得到的错误是 ClassNotFoundException
代表我的服务的接口(JAR实现的)。此接口位于第三个项目中,该项目是我的 war
应用程序的依赖项。
The error I get is a ClassNotFoundException
for the interface that represents my service (which the JAR implements). This interface is in a third project, which is a dependency for my war
application.
推荐答案
tomcat / lib
目录应该用于整个Web服务器的共享库和 WEB-INF / lib
仅适用于一个Web应用程序。
The tomcat/lib
directory should be used for shared libraries for the whole web server and WEB-INF/lib
only for one web application.
这篇关于Tomcat 8类加载 - [WEB-INF / lib]和[tomcat / lib]中的JAR之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!