Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增 JDT 编译方法,以应对没有 JDK 的环境 #43

Closed
subchen opened this issue Dec 9, 2013 · 2 comments
Closed

新增 JDT 编译方法,以应对没有 JDK 的环境 #43

subchen opened this issue Dec 9, 2013 · 2 comments
Assignees
Labels
Milestone

Comments

@subchen
Copy link
Owner

subchen commented Dec 9, 2013

如果只有 jre, 可以 copy 一个 tools.jar 解决。

但是如果允许在第三方的云上面,比如 BAE, GAE,不允许使用 JDK 的 Compiler, 那么可以使用 JDT 来支持编译。

@ghost ghost assigned subchen Dec 9, 2013
@subchen
Copy link
Owner Author

subchen commented Dec 9, 2013

JDT 支持 ServiceLoader 方式载入。

只需要把 org.eclipse.jdt.core_3.9.1.v20130905-0837.jar 放在 classpath 下面就可

javax.tools.JavaCompiler jcc = null;
try {
    jcc = ToolProvider.getSystemJavaCompiler();
} catch(Throwable e) {
    jcc = null;
}
if (jcc == null) {
    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.");
}

@subchen
Copy link
Owner Author

subchen commented Dec 10, 2013

暂时还是用 javax.tools.JavaCompiler 接口来使用 JDT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant