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?
You can request the implementation of JavaCompiler from ToolProvider . If it returns null , the JavaCompiler implementation is not available:
JavaCompiler
ToolProvider
null
JavaCompiler c = ToolProvider.getSystemJavaCompiler(); if (c == null) { // JRE }
Take a look at stackoverflow - How to determine if a Java virtual machine is installed on Windows? How to determine which type of JRE is installed - 32bit versus 64bit and How to determine the installed Sun JRE in Windows?
You can use the System.getProperties()/System.getProperty() method.
System.getProperties()/System.getProperty()
Source: https://habr.com/ru/post/899681/More articles:How to create a client key and secret for registering an application on my site and how to use OAuth to implement a provider - apiDoes an uncontrolled context use performance or portability in C #? - performancehow to create a strong key api - apiHow to delete or create a database from clojure.java.jdbc? - postgresqlDatetime Granularity between 32-bit and 64-bit Windows - c #How to determine if Java Virtual Machine is installed on Windows? - javaANSI C and Function Overloading - cAdjust mysql id column - mysqlIs there a difference between a constructor function and a prototype object when using inheritance? - javascriptiOS UIAutomation: access to user tabs added to UIScrollView in automation script - iosAll Articles