Context context = new Context();
boolean success = false;
Throwable failTrace = null;
try {
Class<?> dfm = Class.forName("com.sun.tools.javac.util.DefaultFileManager");
JavaFileManager instance = (JavaFileManager) dfm.getConstructor(Context.class, boolean.class, Charset.class).newInstance(context, true, Charset.forName("UTF-8"));
context.put(JavaFileManager.class, instance);
success = true;
} catch (Throwable t) {
//Either DFM, or its replacement JFM, exists (or possibly both in odd classpath configurations). If something is wrong, NoMethodDefErrors and the like occur.
failTrace = t;
}
try {
Class<?> jfm = Class.forName("com.sun.tools.javac.util.JavacFileManager");
JavaFileManager instance = (JavaFileManager) jfm.getConstructor(Context.class, boolean.class, Charset.class).newInstance(context, true, Charset.forName("UTF-8"));
context.put(JavaFileManager.class, instance);
success = true;
} catch (Throwable t) {
//Either DFM, or its replacement JFM, exists (or possibly both in odd classpath configurations). If something is wrong, NoMethodDefErrors and the like occur.
failTrace = t;