java - 如何更改tomcat或jetty下的Java webapp 'WEB-INF path'约定

标签 java jakarta-ee tomcat jetty

在 Java Webapp 下,

我想将/WEB-INF/lib设置为D:/somepath/lib

/WEB-INF/classes到E:/somepath/classes

web.xml到F:/somepath/config.xml

如何在 tomcat 或 jetty 下配置这些以更改约定?

最佳答案

规范(Java™ Servlet 规范版本 2.3)仅提及标准文件夹:

The web application classloader must load classes from the WEB-INF/classes directory first, and then from library JARs in the WEB-INF/lib directory.

对于 Tomcat 或 Jetty,您无法使用“开箱即用”提供的功能来做到这一点:

Tomcat :

WebappX — A class loader is created for each web application that is deployed in a single Tomcat instance. All unpacked classes and resources in the /WEB-INF/classes directory of your web application, plus classes and resources in JAR files under the /WEB-INF/lib directory of your web application, are made visible to this web application, but not to other ones.

Jetty :

The normal configuration is for each web context (web application or war file) is given it's own classloader, which has the system classloader as it's parent. Such a classloader hierarchy is normal in Java, however the servlet specification complicates the hierarchy by requiring that:

Classes contained within WEB-INF/lib or WEB-INF/classes have priority over classes on the parent class loader. This is the opposite of the normal behaviour of a java 2 class loader.

但是,您可以:

  1. Add extra classpaths to Jetty
  2. Add directory to Tomcat classpath

干杯

关于java - 如何更改tomcat或jetty下的Java webapp 'WEB-INF path'约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18436539/

相关文章:

Java字符到数字编码的转换

java - 带有显示标签的 struts 1.3 磁贴

java - 从文件位置在 Java 中运行 .exe 文件

java - 使用 GridBagLayout 将 jButton 相对于 JTable 水平居中

java - 我们如何使用 sessionId 取回特定的 session ?

jakarta-ee - 如何将war文件部署到cPanel中并删除项目名称?

java - 在 Web 上下文根之外动态编译和包含 JSP(X)

java - tomcat中Struts2启动时出现404错误

在 netbeans 上工作时,Tomcat 服务器没有在 eclipse 上启动...!

java - 从 java 应用程序调用的 shell 脚本的位置