从Java Web应用程序中的库JAR覆盖类文件 [英] Overriding a class file from a library JAR in a Java web app
问题描述
在我的Java Web应用程序中,我有以下文件:
In my Java web app, I have these files:
/WEB-INF/classes/com/example/Foo.class
/WEB-INF/lib/example.jar <-- contains the class "com.example.Foo"
是否将使用 classes
目录中定义的类而不是 example.jar中定义的类
?
Will the class defined in the classes
directory be used instead of the class defined in example.jar
?
谢谢。
推荐答案
答案取决于在您的容器上,它取决于容器。通常,/ WEB-INF / classes比WEB-INF / lib中的jar文件中的类更受欢迎。
The answer depends upon your container, it is container dependent. In general, /WEB-INF/classes is preferred to classes in a jar file in WEB-INF/lib.
对于 Tomcat ,订单如下:
因此,从Web应用程序的角度来看,类或资源加载按以下顺序查找以下存储库:
Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:
- 引导类您的JVM
- 系统类加载器类
- / WEB-INF /您的Web应用程序类
- 您的Web应用程序的/WEB-INF/lib/*.jar
- 常用类加载器类
- Bootstrap classes of your JVM
- System class loader classes
- /WEB-INF/classes of your web application
- /WEB-INF/lib/*.jar of your web application
- Common class loader classes
但是如果您使用的是其他容器,则需要查阅该服务器的文档。
But if you're using a different container, you need to consult the documentation for that server.
这篇关于从Java Web应用程序中的库JAR覆盖类文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!