Some use-cases require compiling the java file on the fly, hence using a class file with reflection API to the introspection. The scenario might not be frequent and there are plenty of ways to do it, but if you decide to use eclipse compiler (which can be debatable). That's how you can use it:
Map m = new HashMap();
m.put(CompilerOptions.OPTION_Source, System.getProperty("java.specification.version"));
org.eclipse.jdt.internal.compiler.batch.Main main = new org.eclipse.jdt.internal.compiler.batch.Main(new PrintWriter(System.out), new PrintWriter(System.err), false, m , null);
return main.compile(new String[] { "-classpath ", classPathStr, srcFile.getAbsolutePath()});
Comments
Post a Comment