public boolean compileFile( String sourceFile) {
boolean compilationResult = true; // no errors
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler == null) { // Sterg-SOS why not loaded?
System.out.println("ToolProvider.getSystemJavaCompiler: no compiler provided. Unable to compile");
}
DiagnosticCollector<JavaFileObject> diagnostics =
new DiagnosticCollector<JavaFileObject>();
StandardJavaFileManager fileManager =
compiler.getStandardFileManager(diagnostics, null, null);
StringWriter compileWriter = new StringWriter();
List <File> sourceFileList = new ArrayList<File>();
sourceFileList.add(new File(sourceFile));
Iterable<? extends JavaFileObject> compilationUnits =
fileManager.getJavaFileObjectsFromFiles(sourceFileList);
String pathOfFile = sourceFile.substring(0, sourceFile.lastIndexOf(File.separatorChar));
String classpath =GlobalValues.jarFilePath+File.pathSeparatorChar+pathOfFile+File.pathSeparatorChar+".";
Iterable <String> options = Arrays.asList("-cp", classpath);
CompilationTask task = compiler.getTask(compileWriter, fileManager, null, options, null, compilationUnits);
boolean compileResult = task.call();
if (compileResult == false) {
compilationResult = false; // compilation errors
JFrame compResultsFrame = new JFrame("Compilation Results");