java:如何检测当前java运行时是JRE还是JDK?
我有一个 Java 应用程序,我想为用户提供编译 Java 源代码的能力(使用 JavaCompiler 接口)
如果用户在 JRE 上运行该应用程序,我的应用程序应该告诉用户没有可用的 JavaCompiler 实例。
那么如何检测java程序中的JDK或JRE呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从
ToolProvider
请求实现JavaCompiler
。如果它返回null
,则没有可用的JavaCompiler
实现:You can request an implementation of
JavaCompiler
fromToolProvider
. If it returnsnull
, there is no implementation ofJavaCompiler
available:看一下 stackoverflow 线程 - 如何确定如果 Java VM 安装在 Windows 上? , 如何检测哪种 JRE已安装 — 32 位与 64 位 和 如何检测 Windows 上已安装的 Sun JRE?
您可以使用
System.getProperties()/System.getProperty()
方法。Take a look at stackoverflow thread - How to determine if the Java VM is installed on Windows? , How do I detect which kind of JRE is installed — 32bit vs. 64bit and How can I detect the installed Sun JRE on Windows?
You can use
System.getProperties()/System.getProperty()
method.