gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:06 25 4
gpt4 key购买 nike

在 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/classesdirectory 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com