Is there a way to run a program compiled by JavaCompiler? [javax.tools.JavaCompiler]
My code is:
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, prepareFile(nazwa, content)); task.call(); List<String> returnErrors = new ArrayList<String>(); String tmp = new String(); for (Diagnostic diagnostic : diagnostics.getDiagnostics()) { tmp = String.valueOf(diagnostic.getLineNumber()); tmp += " msg: "+ diagnostic.getMessage(null); returnErrors.add(tmp.replaceAll("\n", " ")); }
Now I want to run this program with a lifetime of 1 second and get the output in a string variable. Is there any way to do this?
source share