Java: how to determine the current java environment - JRE or JDK?

I have a Java application, I want to give the user the ability to compile Java source code (using the JavaCompiler interface)

If the user runs the application in the JRE, my application should inform the user that the JavaCompiler instance is not available.

so how to define a jdk or jre in a java program?

+6
source share
2 answers

You can request the implementation of JavaCompiler from ToolProvider . If it returns null , the JavaCompiler implementation is not available:

 JavaCompiler c = ToolProvider.getSystemJavaCompiler(); if (c == null) { // JRE } 
+11
source

Source: https://habr.com/ru/post/899681/


All Articles