ToolProvider.getSystemJavaCompiler() returns null

2019-01-25 02:49发布

I am trying to use the JavaCompiler class:

When I call ToolProvider.getSystemJavaCompiler() it returns null.

I think this is because I'm using a JRE instead of a JDK.

The problem is I want it to run on all platforms regardless of weather the user is using a JRE or a JDK.

If anyone knows how to fix this, or an alternative method to use please comment.

Any help would be appreciated.

标签: java javac
8条回答
一夜七次
2楼-- · 2019-01-25 03:34

here is simple solution that worked for me

I just changed the jre System library to .....Program Files\Java\jdk1.7.0_55\jre instead of ....Program Files\Java\jdk1.7.0_55\bin and it worked for me.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-25 03:40

ToolProvider.getSystemJavaCompiler() is not available.

Is tools.jar missing from the classpath?

Set class path to the tools.jar file which can found in jdk\jre directory.

System.setProperty("java.home", "C:\\Program Files\\Java\\jdk1.7.0_02");

查看更多
登录 后发表回答