Modifying Classpath at Runtime

Java - - Posted on August, 27 at 4:19 pm

A hackish way of modifying the classpath at runtime can be done in a way described at the java forums Modifying Classpath at Runtime
A cleaner approach is to configure your own classloader and set it as the threads context classloader

  1. URL[] urls=new URL[2];
  2. URLClassLoader classLoader=new URLClassLoader(urls);
  3. Thread.currentThread().setContextClassLoader(classLoader);

This is extremely useful if your unit test cases have dependencies that you would like to load at runtime

Posted in Java |

Leave a Reply