3

under a Java Webapp,

I want to set /WEB-INF/lib to D:/somepath/lib

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

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

how to config these under tomcat or jetty to change the convention?

mainlove
  • 278
  • 3
  • 12
  • 1
    I assume you can't do this, since they are all Java EE specifications. But need expert opinion of this. – Pradeep Simha Aug 26 '13 at 04:18
  • You can add directories to the tomcat classpath (affects all of tomcat however, not just one webapp). See http://stackoverflow.com/questions/1300780/adding-a-directory-to-tomcat-classpath – Keith Aug 26 '13 at 04:24
  • If your OS supports links, and if you are running an exploded war, you could make these directories symbolic links. – Keith Aug 26 '13 at 04:25
  • @keith yes, now I am using eclipse which can create 'linked-file' under all kinds of the OS, – mainlove Aug 26 '13 at 04:29
  • 3
    It's not a 'convention'. It's a *specification.* Why do you think you need something different! – user207421 Aug 26 '13 at 09:51
  • For this question to make any sesnse, you ought to explain *why* you want to do this. I suspect yiur real problem is actually something different. – Raedwald Sep 19 '13 at 07:06

2 Answers2

2

The specification (Java™ Servlet Specification Version 2.3) only mentions standard folders:

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.

With Tomcat or Jetty you cannot do it with "out-of-box" provided functionality:

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.

However, you can:

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

Cheers

Community
  • 1
  • 1
serg.nechaev
  • 1,323
  • 19
  • 26
0

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.

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.

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.

Raedwald
  • 46,613
  • 43
  • 151
  • 237