开发者

Use JDK6 to dynamic compile src but after switching to JDK environment still get a null from ToolProvider.getSystemJavaCompiler();

I'm using JDK6 to compile the input src from UI and to run immediately.

But the problem is that by default my app is using the jre not jdk, so:

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();

always return null;

And I noticed that on each server JDK6 is also installed, so I write this to exp开发者_如何学JAVAect solving this problem:

System.setProperty("java.home", "\opt\jdk-i386-60");
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
// Dynamic compile and run app

But it didn't work, maybe java environment will not change to that place I just set immediately, it still got the null object.

So, my question is how you switch your jre environment to jdk and make it effect immediate that we can get the JavaCompiler object?

Thanks.


Don't try to set java.home! Setting it via a command line switch will usually lead to lots of trouble (libraries not found, ...). Setting it via setProperty() will usually have no affect.

Instead, if you want to execute your application with a specific Java installation, simply use its java executable to start your app:

/opt/jdk-i386-60/bin/java -jar myApp.jar
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜