在 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.
但是,您可以:
干杯
关于java - 如何更改tomcat或jetty下的Java webapp 'WEB-INF path'约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18436539/