//get the current class loader ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); //define paths you want on your classpath URL urls[] = new URL[]{ new File("somedir/somedir2/somedir3").toURI().toURL(), new File("someOtherDir/someOtherDir2/someOtherDir3").toURI().toURL() }; //create a new class loader with the new paths and the old classloader ClassLoader newClassLoader = new URLClassLoader(urls, getClass().getClassLoader()); //set the new classloader as the classloader for this thread. Thread.currentThread().setContextClassLoader(newClassLoader);
Tuesday, 6 November 2012
Adding to Classpath at Runtime
Sometimes you need to add a classpath to your application at runtime. I grappled with this problem when writing a maven plugin, with the abstract mojo class (You would think the mojo class from maven would be aware of the project classpaths, but nope). Anyway heres how to do it.
Subscribe to:
Post Comments (Atom)
-
Heres a quick example to show how annotations can be used as join points in AOP. The code below simply times the execution of any method wit...
-
In many database driven applications it can be useful to automate the testing of SQL against a real database. However setting up and maintai...
-
This post outlines the usages of datalakes and data warehouses. Source: https://www.kdnuggets.com/2015/09/data-lake-vs-data-warehouse...
No comments:
Post a Comment