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

StackOverflow https://stackoverflow.com/questions/5907451

  •  29-10-2019
  •  | 
  •  

문제

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 expect 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.

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top