Created
December 31, 2014 21:32
-
-
Save tylertreat/e0fb625448a387998347 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void addClasspathDependencies() { | |
| String workingDir = System.getProperty("user.dir"); | |
| // We need to add these libs to appease the ClassLoader Gods | |
| File lib = new File(workingDir + File.separator + "lib"); | |
| for (File file : lib.listFiles()) | |
| addToClasspath(file); | |
| // Add bin-test to the class path -- this is where the stubs are | |
| File binTest = new File(workingDir + File.separator + "bin-test"); | |
| addToClasspath(binTest); | |
| } | |
| private void addToClasspath(File file) { | |
| if (!file.exists()) { | |
| logger.error("Could not add " + file.getName() + " to classpath (does not exist)"); | |
| return; | |
| } | |
| URLClassLoader classLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader(); | |
| try { | |
| // Instead of subclassing URLClassLoader, let's just use reflection | |
| URL url = file.toURI().toURL(); | |
| Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); | |
| method.setAccessible(true); | |
| method.invoke(classLoader, url); | |
| } catch (Throwable tr) { | |
| logger.error("Could not add " + file.getName() + " to classpath", tr); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment