Servlet容器和类路径 [英] Servlet containers and classpath

查看:112
本文介绍了Servlet容器和类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Servlet容器集的类路径是什么?

To what is the class path of a Servlet container set?

根据我的理解,涉及三个组成部分。 Servlet容器的 lib 目录中的JAR文件,然后是 WEB-INF / classes 和JAR中的类 WEB-INF / lib 目录中的文件。 Servlet容器的 lib 目录中的类被添加到系统类路径中,动态类路径包含 lib 目录中的目录和类。

As per my understanding there are three components involved. The JAR files in the lib directory of the Servlet container and then the classes in the WEB-INF/classes and JAR files in the WEB-INF/lib directory. The classes in lib directory of the Servlet container are added to the system classpath and the dynamic classpath includes the JAR files in the lib directory and classes in the classes directory.

什么是动态类路径集?动态类路径是指向 WEB-INF 下的所有目录,还是包含 WEB-INF / lib WEB-INF / classes 或只是指向两个目录 WEB-INF / classes WEB-INF / lib中?假设我在 WEB-INF 中有一个名为 foo 的目录,其中包含 bar.properties 。现在 bar.properties 也在类路径中?

To what is the dynamic classpath set? Does the dynamic classpath point to all the directories under WEB-INF or includes all the individual classes and JAR files in WEB-INF/lib and WEB-INF/classes or just points to the two directories WEB-INF/classes and WEB-INF/lib? Say I have a directory called foo in WEB-INF containing bar.properties. Now is bar.properties also in the class path?

推荐答案

dynamic类路径将列出 WEB-INF / classes ,每个JAR文件在 WEB-INF / lib 下单独存在条目。 WEB-INF 下的其他文件夹包含

The "dynamic" classpath will list WEB-INF/classes, each JAR file under WEB-INF/lib as a separate entry. Other folders under WEB-INF are not included.

在您的示例中, bar.properties 将不在类路径中。将其移至 WEB-INF / classes ,或将其放在 WEB-INF / lib 下的JAR文件中。

In your example, bar.properties will not be on the classpath. Move it to WEB-INF/classes, or put it inside a JAR file under WEB-INF/lib.

类路径的其余部分取决于您的Servlet容器。它是特定于实现的,但是大多数容器还有两个放置类的地方。一个是容器可见的目录,但不是应用程序,另一个对容器和所有应用程序都是可见的。由于第二个 ClassLoader 对所有应用程序都可见, static 这些类的成员可用于在申请。

What's in the rest of the classpath depends on your Servlet container. It is implementation-specific, but most containers have two other places to put classes. One is a directory that is visible to the container, but not the applications, and the other is visible to the container and all of the applications. Since the second ClassLoader is visible to all of the applications, static members of those classes can be used to share information between applications.

这篇关于Servlet容器和类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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