How to tell if JDK is available from within running JVM?

Class.forName("com.sun.tools.javac.Main");

If there is no exception, it is a JDK.

It works with current JDKs, but it's probably not part of any official spec.


javax.tools.ToolProvider.getSystemJavaCompiler() will return null if no compiler is available, and a JavaCompiler if it is.

Technically it just tells you if the compiler is available of course, but that in most scenarios will imply the existence of the JDK.

Tags:

Java

Jvm

Liferay