通常,JNLP只能从http:/https:URL下载。例如:
URL url = new URL(
"https://docs.oracle.com/javase/tutorialJWS/samples/uiswing/WallpaperProject/Wallpaper.jnlp");
// Downloading and starting the application...
final File jnlp = File.createTempFile("temp", ".jnlp");
try (InputStream is = url.openStream();
FileOutputStream fos = new FileOutputStream(jnlp)) {
byte[] buffer = new byte[8192];
int len;
while ((len = is.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
}
System.out.println("JNLP file written to " + jnlp.getAbsolutePath());
//Desktop.getDesktop().open(jnlp);
new ProcessBuilder("cmd", "/c", "javaws", jnlp.getAbsolutePath())
.start();
不确定这是为了什么环境。在我发现的窗户下
Desktop.open()
没有启动,因此直接调用
javaws
.
如果直接打给
爪哇
是一个选项,但是有一个更简单的方法,因为它可以直接从URL启动JNLP文件:
new ProcessBuilder("cmd", "/c", "javaws",
"https://docs.oracle.com/javase/tutorialJWS/samples/uiswing/WallpaperProject/Wallpaper.jnlp")
.start();