title: Integrating a third-party API into a Java application with clashing dependencies
body: <p>I am working on an existing application which has quite a lot of external JAR dependencies. I need to enhance it to integrate with a third-party application which has an API. Sadly, the API is not well contained and also comes with a large number of its own dependencies some of which clash with mine.</p>
  
  <p>I believe I should solve this using Classloaders, but I'm struggling to see how to structure them correctly.</p>
  
  <p>To keep it simple, assume we have myapp.jar with a hibernate3.jar dependency, and vendor-api.jar with a hibernate2.jar dependency (and assume these are incompatible).</p>
  
  <p>My new piece of code will reside in the myapp.jar library (although it could be in a separate jar if this would help). Due to the way the vendor API works, my new code needs to  extend a class from the vendor-api.jar library. </p>
  
  <p>How can I structure the Classloaders in such a way that anything within the vendor-api.jar accesses only its own dependencies, and anything on my side accesses only the myapp.jar and dependencies?</p>
  
  <p>Thanks, Jon</p>