title: Need two versions of a jar file used for different classes
body: <p>I've done a lot of searching and haven't found an answer to this question.  Maybe this can't be done, but here's what I have</p>
  
  <ol>
  <li>A.jar depends on SomeLibrary-V2.jar   </li>
  <li>Class1 in A.jar depends (indirectly) on SomeLibrary-V1.jar.</li>
  </ol>
  
  <p>and I'd like </p>
  
  <ol>
  <li>A.jar to get its classes from V2 </li>
  <li>Class1 (and the classes it triggers loading for) to get the V1 classes or classes from A.jar as necessary.</li>
  </ol>
  
  <p>I can write my own <a href="https://stackoverflow.com/questions/5445511/how-do-i-create-a-parent-last-child-first-classloader-in-java-or-how-to-overr">child-first classloader</a> to load Class1 by name when needed.  This classloader will then search SomeLibrary-V1.jar first (before the parent classloader).  However, the classloader for Class1 will not be set to my classloader since it will defer to a parent.  This then means that my child classloader will not be used when Class1 tries to load a class which I want to come from SomeLibrary-V1.jar.  </p>
  
  <p>I think I need my classloader to be set as the classloader for  Class1 class. I've looked at introspection to set the class loader to my classloader instance, but the classLoader field of the Class objects is not exposed.  Another way might be to call definedClass() from my classloader, but then I can't really use the parents. </p>
  
  <p>I've seen <a href="https://stackoverflow.com/questions/1553567/java-classloader-how-to-reference-different-versions-of-a-jar">this</a> but the answer there suggests  writing a classloader but provides no details.  I have provided some details here that call out additional questions/problems with that solution (I hope - and I didn't have the rep to add a comment).</p>
  
  <p>I hope I'm just missing something here. Thanks for any help.</p>