Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: how to detect the current java runtime is a JRE or JDK?

I got a Java application, I want to provide user ability to compile Java source code (Using JavaCompiler interface)

If the user run the application on a JRE, my application should tell user that the no JavaCompiler instance aviable.

so how to detect JDK or JRE in java programe?

like image 709
CaiNiaoCoder Avatar asked Oct 20 '11 09:10

CaiNiaoCoder


People also ask

How do I know if I have Java JDK or JRE?

You might have either JRE(Java Runtime Environment) which is required to run java applications on the computer or JDK as shown below. 1. Open command prompt and enter “java –version”. If installed version number is displayed.

Which version of Java is currently running?

What is the latest Java version? As of September 2022, Java 19 is the latest released Java version.

Can you tell difference between a JDK JRE JVM?

The JRE is an abbreviation for Java Runtime Environment. The JVM is an abbreviation for Java Virtual Machine. The JDK (Java Development Kit) is a software development kit that develops applications in Java. Along with JRE, the JDK also consists of various development tools (Java Debugger, JavaDoc, compilers, etc.)


1 Answers

You can request an implementation of JavaCompiler from ToolProvider. If it returns null, there is no implementation of JavaCompiler available:

JavaCompiler c = ToolProvider.getSystemJavaCompiler();
if (c == null) {
    // JRE
}
like image 141
axtavt Avatar answered Oct 19 '22 22:10

axtavt