Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a .war file in Tomcat server. The .war file contains a file that I would like to override. The webapp will load up the file from the classpath.

How can I modify the classpath so that the server will load an another file from the local disk instead? Basically I should add to start the classpath the directory where my replacement file resides. How can I do that?

share|improve this question

Unfortunately, Java works on a first-come, first-serve basis. If you have two identical files in two different jars, for example, whichever one appears first in Tomcat's classpath hierarchy will be used. The Tomcat 5.5 documentation talks about the order specifically.

So if you'd like to have one library take precedence over the other, you'll have to make sure that the one receiving precedence appears (alphabetically) before the one you want to be overwritten in WEB-INF/lib.

(BTW, this is what is infamously known as jar hell)

share|improve this answer
I do know how the java classpath operates. I'd like to know how I can manipulate classpath in Tomcat so that I could override one of the files inside war. – Juha Syrjälä Sep 2 '10 at 5:41
I did, check the second paragraph. Unzip the war, go to WEB-INF/lib, and plop the library you want to use as the override into that directory, with a name that precedes the one you want overriden. Usually, numbers work--i.e., 10-somelibrary.jar would come before somelibrary.jar. You can't directly manipulate the classpath in Tomcat5. – Andrew M. Sep 2 '10 at 12:18
Ok, I was hoping that there would some less intrusive method. I would prefer if I didn't have to change contents of the war file. – Juha Syrjälä Sep 2 '10 at 18:57
Unfortunately, .war files are supposed to be entirely self contained web applications, which means everything you need to run it should be there. A better question might be, why are you trying to do this? But that would be a task for another question. :) – Andrew M. Sep 3 '10 at 1:57
Typically one would like to use same war file in production and testing environment. But there need to be different configuration files depending on the environment. – Juha Syrjälä Sep 3 '10 at 12:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.