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