Skip to content

Commit

Permalink
Fixed #43 lookup JDT implements when tools.jar not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
subchen committed Dec 10, 2013
1 parent 7110b50 commit 696fa7f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/jetbrick/template/compiler/jdk/JdkCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,20 @@ public class JdkCompiler extends JavaCompiler {
public JdkCompiler(JetTemplateClassLoader classloader) {
super(classloader);

this.jc = ToolProvider.getSystemJavaCompiler();
if (jc == null) {
javax.tools.JavaCompiler jcc = ToolProvider.getSystemJavaCompiler();
if (jcc == null) {
// JDT 支持 ServiceLoader 方式载入。
ServiceLoader<javax.tools.JavaCompiler> serviceLoader = ServiceLoader.load(javax.tools.JavaCompiler.class);
Iterator<javax.tools.JavaCompiler> iterator = serviceLoader.iterator();
if (iterator.hasNext()) {
jcc = iterator.next();
}
}
if (jcc == null) {
throw new IllegalStateException("Can't get system java compiler. Please add jdk tools.jar to your classpath.");
}

this.jc = jcc;
this.fileManager = jc.getStandardFileManager(null, null, null);
this.options = Arrays.asList("-encoding", encoding, "-g", "-nowarn");

Expand Down

0 comments on commit 696fa7f

Please sign in to comment.