2005-05-03

ClassLoader.getResource() in a Tomcat instance

If you happen to run a setup with multiple Tomcat instances and you're wanting to load a resource from the shared/classes directory:

  • Create the shared/classes directory within the instance's own directory, alongside your webapps-dir.
  • Now you can use Thread.currentThread().getContextClassLoader().getResource() to access all files in there.

It just took me two hours to figure out the obvious (in hindsight): shared/ is by no means shared by all the instances of the same CATALINA_HOME — it's one shared/ per instance. I think I'll have this tatoo'd on some bodypart.

Lest I forget: A really nice explanation on setting up multiple tomcat instances is Codesta's Installing Tomcat on Apache . Sadly so, they miss the shared-directory!!! And what to think about Tomcat's own documentation, a quip from "Rusty" Harold comes to mind: "… the documentation ranges from poor to actively misleading …" (5. July 2004)

Keine Kommentare: