vda8888
vda8888

Reputation: 707

ToolProvider.getSystemJavaCompiler() returning null in JDK 9

My project in Eclipse is running WITH SYSTEM JRE 9. When I try to set Java home to JDK 9 to get the system compiler I got null.

System.setProperty("java.home", "C:\\Program Files\\Java\\jdk-9.0.1");
System.out.println(System.getProperty("java.home")); // print C:\Program Files\Java\jdk-9.0.1
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); // returns null

This code previously works fine with JDK 8 (running from JRE 8)

System.setProperty("java.home", "C:\\Program Files\\Java\\jdk1.8.0_152");
System.out.println(System.getProperty("java.home")); // print C:\Program Files\Java\jdk1.8.0_152
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); // returns compiler

Has there been any change to how ToolProvider.getSystemJavaCompiler requirement works?

Update: not sure if it matters but getSystemJavaCompiler() works fine if I run my project from JDK 9 (change to java.home is no longer required) as opposed to JRE 9.

Upvotes: 3

Views: 1356

Answers (1)

Naman
Naman

Reputation: 32028

Correspondingly changing the path on Unix to /Contents/Home works for me :

System.setProperty("java.home", 
                   "/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/");

Though there doesn't seem to be a need of setting the property at all. Since the following line of code even independently executes fine as well:

JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); 

with JAVA_HOMEon my system set to point to JDK9 Home directory.

Upvotes: 1

Related Questions