try {
File inFile = new File(sourcePath + File.separator + className + ".java");
File outFile = new File(sourcePath + File.separator + className + ".class");
ByteArrayOutputStream errorOutputStream = new ByteArrayOutputStream();
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) {
throw new RuntimeException("Could not locate a compiler. You may be running in a JRE and not a JDK. " +
"For the purpose of development mode Errai requires the use of a JDK so it may produce server " +
"marshalling code on-the-fly.");
}
/**
* Attempt to run the compiler without any classpath specified.
*/
if (compiler.run(null, null, errorOutputStream, inFile.getAbsolutePath()) != 0) {
errorOutputStream.reset();
/**
* That didn't work. Let's try and figure out the classpath.
*/
StringBuilder sb = new StringBuilder();
List<URL> configUrls = MetaDataScanner.getConfigUrls();
List<File> classpathElements = new ArrayList<File>(configUrls.size());
for (URL url : configUrls) {
File file = getFileIfExists(url);
if (file != null) {
classpathElements.add(file);
}
}
for (File file : classpathElements)
sb.append(file.getAbsolutePath()).append(File.pathSeparator);
sb.append(System.getProperty("java.class.path"));
sb.append(findAllJarsByManifest());
if (compiler.run(null, null, errorOutputStream, "-cp", sb.toString(), inFile.getAbsolutePath()) != 0) {
System.out.println("*** FAILED TO COMPILE MARSHALLER CLASS ***");
System.out.println("*** Classpath Used: " + sb.toString());
for (byte b : errorOutputStream.toByteArray()) {