title: Conflicting JARs: shouldn't WEB-INF/lib take precedence over all others places?
body: <p>My deployment environment is very messed up: jar files are scattered all over the system, and I have no control on it. For example my webapp uses a recent version of Javamail API, but is seems that in <code>$JAVA_HOME/jre/lib/ext</code> there are multiple copies of the same library (obviously all older and different versions). The same applies for database vendors' drivers, not to mention <code>$CATALINA_HOME/lib</code>. <strong>I can't clean up anything</strong>, but obviously I need to ensure that my app gets the minimum required version of its dependencies, so I put all the required JARs in <code>WEB-INF/lib</code>. According to Servlet spec and <a href="http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html" rel="nofollow">Tomcat docs</a>:</p>
  
  <blockquote>
    <p>When a request to load a class from the web application's WebappX
    class loader is processed, this class loader will look in the local
    repositories first, instead of delegating before looking</p>
  </blockquote>
  
  <p>so it should solve my problem. But then the very same doc says:</p>
  
  <blockquote>
    <p>Therefore, from the perspective of a web application, class or
    resource loading looks in the following repositories, in this order:</p>
    
    <ol>
    <li>Bootstrap classes of your JVM</li>
    <li>System class loader classes (described above)</li>
    <li>/WEB-INF/classes of your web application</li>
    <li>/WEB-INF/lib/*.jar of your web application</li>
    <li>Common class loader classes (described above)</li>
    </ol>
  </blockquote>
  
  <p>And actually the classes in <code>/WEB-INF/lib</code> are loaded <strong>after</strong> system ones. Is this indeed expected behavior? Don't you find that the Tomcat docs is contradictory? Do you know any servlet container which guarantees that I can get the correct dependencies? How can I solve this problem? </p>