Does the Java compiler support only jar files with manifests with Class-Path
in classpath arguments?
I am trying to use the Java Compiler API in Maven Surefire tests, but it seems that the Java Compiler API, or rather ToolProvider.getSystemJavaCompiler()
, is not processing the Surefire manifest banks properly.
Here is a piece of code that shows a failed test
new File("target/out").mkdir(); JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); URLClassLoader classLoader = (URLClassLoader)Thread.currentThread().getContextClassLoader(); // create classpath StringBuilder path = new StringBuilder(); for (URL url : ((URLClassLoader) classLoader).getURLs()) { if (path.length() > 0) { path.append(File.pathSeparator); } String decodedPath = URLDecoder.decode(url.getPath(), "UTF-8"); path.append(new File(decodedPath).getAbsolutePath()); } System.err.println(path); // compile List<String> options = Arrays.asList( "-classpath", path.toString(), "-s", "target/out", "src/test/java/com/mysema/codegen/SimpleCompilerTest.java"); int compilationResult = compiler.run(null, null, null, options.toArray(new String[options.size()])); if (compilationResult != 0) { Assert.fail("Compilation Failed"); }
source share