简体   繁体   English

如何在tomcat或jetty下更改Java webapp'WEB-INF路径'约定

[英]How to change the Java webapp 'WEB-INF path' convention under tomcat or jetty

under a Java Webapp, 在Java Webapp下,

I want to set /WEB-INF/lib to D:/somepath/lib 我想将/ WEB-INF / lib设置为D:/ somepath / lib

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

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

how to config these under tomcat or jetty to change the convention? 如何在tomcat或jetty下配置这些来改变约定?

The specification (Java™ Servlet Specification Version 2.3) only mentions standard folders: 规范(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. Web应用程序类加载器必须首先从WEB-INF / classes目录加载类,然后从WEB-INF / lib目录中的库JAR加载类。

With Tomcat or Jetty you cannot do it with "out-of-box" provided functionality: 使用Tomcat或Jetty,您无法使用“开箱即用”提供的功能:

Tomcat : Tomcat

WebappX — A class loader is created for each web application that is deployed in a single Tomcat instance. WebappX - 为部署在单个Tomcat实例中的每个Web应用程序创建一个类加载器。 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. Web应用程序的/ WEB-INF / classes目录中的所有解压缩的类和资源,以及Web应用程序的/ WEB-INF / lib目录下的JAR文件中的类和资源,都对此Web应用程序可见,但不是到其他人。

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. 正常配置是为每个Web上下文(Web应用程序或war文件)提供它自己的类加载器,它具有系统类加载器作为它的父级。 Such a classloader hierarchy is normal in Java, however the servlet specification complicates the hierarchy by requiring that: 这样的类加载器层次结构在Java中是正常的,但是servlet规范通过要求以下内容使层次结构复杂化:

Classes contained within WEB-INF/lib or WEB-INF/classes have priority over classes on the parent class loader. WEB-INF / libWEB-INF / classes中包含的优先于父类加载器上的类。 This is the opposite of the normal behaviour of a java 2 class loader. 这与java 2类加载器的正常行为相反。

However, you can: 但是,您可以:

  1. Add extra classpaths to Jetty 为Jetty添加额外的类路径
  2. Add directory to Tomcat classpath 将目录添加到Tomcat类路径

Cheers 干杯

On a Unix system you could do this manually by setting up soft links from the expected places to the locations on the other disks. 在Unix系统上,您可以通过设置从预期位置到其他磁盘上的位置的软链接来手动执行此操作。

Both application servers you mention are open source, so you could write your own version of them. 您提到的两个应用程序服务器都是开源的,因此您可以编写自己的版本。 I guess the part that implements the classloader for a web app is what you would have to change. 我想实现Web应用程序的类加载器的部分是您必须更改的部分。

But if you must engage in such shenanigans, you should suspect that you have made a wrong decision earlier. 但是,如果你必须参与这样的诡计,你应该怀疑你早些时候做出了错误的决定。 I can think of no good reason to do what you want to do. 我认为没有理由去做你想做的事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将inputstream转换为java中tomcat中web-inf文件夹下的配置文件? - how to get the inputstream to configuration file lying under web-inf folder in tomcat in java? 如何在Java类中的WEB-INF文件夹下访问文件 - How to access a file under WEB-INF folder in java class Struts 2 Convention插件和WEB-INF下的JSP文件 - Struts 2 Convention Plugin and JSP files under WEB-INF 当WEB-INF中有许多文件时,Tomcat Webapp启动缓慢 - Slow Tomcat Webapp start when lots of files in WEB-INF Maven将Tomcat JAR复制到webapp WEB-INF / lib目录 - Maven copying Tomcat JARs into webapp WEB-INF/lib directory 如何将.Readata的getRealPath(“/”)路径更改为WEB-INF - How to change getRealPath(“/”) path from .metadata to WEB-INF webapp / WEB-INF或src / main / resources下的资源文件? - resource files under webapp/WEB-INF or src/main/resources? 如何获取WEB-INF / class文件夹下的资源路径(java ee web动态项目) - How can I get path of resource under WEB-INF/class folder (java ee web dynamic project) Java WebApp:从位于WEB-INF的.jar加载资源 - Java WebApp: Loading resource from .jar located in WEB-INF 找不到Tomcat类,并且路径WEB-INF \\ lib中有该类 - Tomcat class not found & there is the class in the path WEB-INF\lib
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM