CompileCP { static String compileFromClassPath(URL u, final Res r) throws IOException { File f; try { f = new File(u.toURI()); } catch (URISyntaxException ex) { throw new IOException(ex); } String s = f.isDirectory() ? f.getPath() : null; for (String candidate : System.getProperty("java.class.path").split(File.pathSeparator)) { if (s != null) { break; } if (f.getPath().startsWith(candidate)) { s = candidate; } } if (s != null) { File root = new File(s); StringWriter w = new StringWriter(); try { Bck2BrwsrJars.configureFrom(null, root) .generate(w); w.flush(); return w.toString(); } catch (ClassFormatError ex) { throw new IOException(ex); } finally { w.close(); } } return null; }    }
@Test public void compileClassPath() throws Exception { URL u = CompileCPTest.class.getResource("/" + CompileCPTest.class.getName().replace('.', '/') + ".class"); assertNotNull(u, "URL found"); assertEquals(u.getProtocol(), "file", "It comes from a disk"); String resources = CompileCP.compileFromClassPath(u, null); assertNotNull(resources, "something compiled"); }