Detect if certain software is installed on a user#39;s machine in Java(检测某些软件是否安装在 Java 中的用户机器上)
问题描述
我有一个 Java 应用程序,它需要某些软件(其中之一是 Perl)才能运行.我用来检测 Perl 的方法是:
I have a Java application which requires certain software (one of them being Perl) before it can be run. What I used to do to detect for Perl is:
Runtime.getRuntime().exec("perl Test.pl");
如果有 IOException 则声明没有 Perl.
and if there was an IOException declare that there was no Perl.
但是,我的一位用户抱怨该应用程序一直失败,因为他没有将 Perl 放在他的路径变量中.所以这就是我要问的原因:是否有任何跨操作系统的方法来检测用户系统上是否安装了 Perl(或任何其他软件)以及程序的路径?
However, one of my users complained that the app kept failing because he had not placed Perl in his path varible. So this is why I'm asking: Is there any cross-operating system way to detect whether Perl (or any other software) is installed on the user's system and the path to the program?
推荐答案
我不知道你的目标受众(用户),但失败时你可以提示用户输入路径(一个 FileChooserDialog)然后存储这个路径以备将来使用(如果没有再次抛出异常).前段时间我这样做了,幸运的是我的用户是系统管理员,所以他们可以在第一次发生错误时提供该信息(我还记录了如何在属性文件中更新或更改这些值).
I don't know your target audience (users), but upon failure you could prompt the user to enter the path (a FileChooserDialog) and then store this path for future usage (if the exception is not thrown again). I did that some time ago, luckily I had users that were SysAdmins, so it was OK for them to provide that info when the error happened the first time (I also documented how to update or change these values in a properties file).
Don 提到的其他选项是安装相对于您的安装所需的软件,这是一个更常见的选项.
Other option as mentioned by Don, is to install the required software as relative to your installation, that's a more common option.
这篇关于检测某些软件是否安装在 Java 中的用户机器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:检测某些软件是否安装在 Java 中的用户机器上
基础教程推荐
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- JPA惰性列表上的流 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- Maven:无效的目标版本:10 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
