检测某些软件是否安装在 Java 中的用户机器上

Detect if certain software is installed on a user#39;s machine in Java(检测某些软件是否安装在 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 中的用户机器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to implement RecyclerView with section header depending on category?(如何根据类别实现带有节标题的 RecyclerView?)
How to generate JNI header file in Eclipse(如何在 Eclipse 中生成 JNI 头文件)
Setting a custom HTTP header dynamically with Spring-WS client(使用 Spring-WS 客户端动态设置自定义 HTTP 标头)
Could you technically call the string[] anything in the main method?(从技术上讲,您可以在 main 方法中调用 string[] 吗?)
What is the proper way of setting headers in a URLConnection?(在 URLConnection 中设置标头的正确方法是什么?)
How to overwrite http-header quot;Hostquot; in a HttpURLConnection?(如何覆盖 http-header “主机在 HttpURLConnection 中?)