以编程方式确定我的盒子上安装了哪些JDK/JRE [英] Programmatically determine what JDK/JRE's are installed on my box

查看:63
本文介绍了以编程方式确定我的盒子上安装了哪些JDK/JRE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有标准方法可以做到这一点?我意识到这可能与平台有关.目前我们的产品仅在Windows上受支持-所以我想这就是我现在感兴趣的产品.我唯一能想到的就是扫描注册表或对文件系统进行爬网.扫描文件系统似乎可能需要很长时间-并且注册表可能不可靠.我应该两个都做吗?还有其他建议吗?我试图寻找一种可以做到这一点的API.

Is there a standard way to do this? I realize this can be somewhat platform dependent. Our product right now is only supported on Windows - so I suppose that's what I'm interested in right now. The only things I can think of are to either scan the registry or crawl the file system. Scanning the file system seems like it can take a really long time - and the registry can be unreliable. Should I do both? Any other suggestions? I tried to look for an API to do this with no luck.

推荐答案

首先,我将寻找JAVA_HOME环境变量(可能还有JDK_HOME,尽管那并不常见),然后确定是哪个版本以及它是否为JDK.或JRE.

I would firstly start by looking for the JAVA_HOME environment variable (and possibly JDK_HOME although thats far less common) and then determining what version that is and whether it's a JDK or JRE.

之后,请检查常见的位置.找出系统的程序文件目录(即使是99.5%的时间,也不要仅假设它是C:\ Program Files),然后在该目录下查找常见的安装位置(例如Java).

After that check for common instead locations. Find out the system's program files directory (don't just assume it's C:\Program Files even though it is 99.5% of the time) and look for common install locations under that (eg Java).

我不会进行详尽的搜索.

I wouldn't do an exhaustive search.

值得一问:您真的需要这种方式找到JDK吗?您能不能仅问用户他或她想使用什么JDK,并可能建议您已经找到了任何简单的JDK?

It's worth asking: do you really need to find JDKs this way? Can't you just ask the user what JDK he or she wishes to use, possibly suggesting any easy ones you've found already?

这篇关于以编程方式确定我的盒子上安装了哪些JDK/JRE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆