简体   繁体   English

从应用程序安装Java Web Start

[英]Install Java Web Start from an Application

I have a simple Java program that uses: 我有一个简单的Java程序,它使用:

Runtime.getRuntime().exec("/usr/bin/javaws", [path for JNLP file]) 

to open a JNLP file using java web start. 使用Java Web Start打开JNLP文件。

However, I need to deal with the scenario of javaws not being installed. 但是,我需要处理未安装javaws的情况。 So I need to check to see if it is installed and, if it's not, install it. 因此,我需要检查是否已安装,如果未安装,请安装它。 Any idea how to do either of those (or both)? 任何想法如何做这些(或两者)?

Firstly, you're assuming that the path to javaws is /usr/bin/javaws , which may not be the case. 首先,您假设javaws的路径是/usr/bin/javaws ,但事实并非如此。

If it were that simple, then you can check if the file exists: 如果就这么简单,那么您可以检查文件是否存在:

File javawsFile = new File("/usr/bin/javaws");
if (! javawsFile.exists()) {
    System.out.println("javaws not installed");
} 

Having said that, java does not have to be installed to any particular location. 话虽如此,不必将Java安装到任何特定位置。 Thus you can't assume it's in /usr/bin/ . 因此,您不能假定它在/usr/bin/ Many people will download the java binary zip and simply decompress it to their choice of location, and set the environment variable JAVA_HOME . 许多人会下载Java二进制zip并将其解压缩到他们选择的位置,然后设置环境变量JAVA_HOME

Now, you could go down the path of resolving the JAVA_HOME variable - but even then it'll only tell you if javaws is installed - or not. 现在,您可以JAVA_HOME解析JAVA_HOME变量的路径了-但是即使那样,它也只会告诉您是否已安装javaws-是否安装。

If javaws is not installed, there is not really a way to install it - other than prompting the user to go off to the java website and download it. 如果未安装javaws,则实际上没有安装它的方法-除了提示用户转到java网站并下载它之外。

The path you give is in *nix style. 您提供的路径是* nix样式。 In this case it would require root access to install new applications - which isn't something you can simply manufacture. 在这种情况下,需要root用户权限才能安装新应用程序-这不是您可以简单制造的。

Even if your user was already running your application as root, I would still be wary of this. 即使您的用户已经以root用户身份运行您的应用程序,我仍然对此保持警惕。 It's not your responsibility to install software on your users' machines. 在用户的计算机上安装软件不是您的责任。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM