2012-07-26 46 views
5

我制作了一个Java webstart应用程序,并创建了一个带有链接的HTML页面来启动它。问题是,在谷歌浏览器中,没有选项可以在不保存的情况下“打开”文件。我想制作一个HTML页面,可以自动启动一个JNLP文件,而不必保存它。或者说,没有用户不得不打开他们的文件资源管理器来启动它)这可能吗?无需下载...启动webstart ...?

+0

相关:HTTP://计算器。 com/questions/9348449/can-i-delete-downloaded-jnlp-file-java-web-start-jws-from-java-application – finnw 2012-07-27 08:46:18

回答

2

使用使用web start部署的嵌入式applet启动JNLP。

  1. 开始与基于JApplet的一个Swing接受的图像路径(图标),并为按钮的字符串。使用JWS部署小程序(嵌入网页中的链接所在的位置)。
  2. 当用户单击该按钮时,使用BasicService.showDocument(URL)方法启动JWS(基于框架)应用程序。正如我注意到在demo. of the BasicService ..

    ..In的Java 6+,呼叫显示其它网站开始启动文件(例如:BasiceService.showDocument(another.jnlp))直接交给javaws的,没有浏览器窗口出现。

+1

好的,但在chrome中,它并没有交给JavaWS。它打开一个浏览器窗口..... – DankMemes 2012-07-27 19:08:42

+3

此外,Chrome停止支持小程序。 – 2016-03-04 13:19:46

2

不幸的是,这是在谷歌浏览器的错误(/功能?)这still exists,但它是部分固定:现在就可以自动打开JNLP文件,但他们仍然保存在下载文件夹

  • 下载JNLP
  • 在下载栏中点击右键并选择这种类型
  • 点击JNLP现在直接的总是打开的文件启动它
+3

他们已经阻止了jnlps的“始终打开”选项。很烦人。请在下面的答案中查看我的挫折结果,以获得解决方法。 – 2015-10-23 04:02:37

4

受够了这个问题之后,我写了我自己的工作围绕扩展。

这是在Ubuntu下编写的,但应该是可移植的(甚至有一些工作/阅读win32)。

单击无需启动或下载即可启动jnlp文件。它只是将jnlp文件的url直接传递给javaws。没有混乱的下载文件夹,没有额外的点击。

它简单,粗糙,有效。我过滤了URL,所以它只适用于我自己的内部服务器,所以我不会意外启动一些随机jnlp文件。我敢肯定,可以做更多的事情来改善它。使用AS-IS,没有担保,等等,等等

的文件:

在/ usr/local/bin目录/ JNLP - 发射

#!/usr/bin/env python 

import struct 
import sys 
import threading 
import Queue 
import json 
import os 


# On Windows, the default I/O mode is O_TEXT. Set this to O_BINARY 
# to avoid unwanted modifications of the input/output streams. 
if sys.platform == "win32": 
    import os, msvcrt 
    msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) 
    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) 

# Helper function that sends a message to the webapp. 
def send_message(message): 
    # Write message size. 
    sys.stdout.write(struct.pack('I', len(message))) 
    # Write the message itself. 
    sys.stdout.write(message) 
    sys.stdout.flush() 

# Thread that reads messages from the webapp. 
def read_thread_func(queue): 
    message_number = 0 
    while 1: 
    # Read the message length (first 4 bytes). 
    text_length_bytes = sys.stdin.read(4) 

    if len(text_length_bytes) == 0: 
     if queue: 
     queue.put(None) 
     sys.exit(0) 

    # Unpack message length as 4 byte integer. 
    text_length = struct.unpack('i', text_length_bytes)[0] 

    # Read the text (JSON object) of the message. 
    text = sys.stdin.read(text_length).decode('utf-8') 

    decoded = json.loads(text); 
    os.system("javaws " + decoded['url']); 


def Main(): 
    read_thread_func(None) 
    send_message('"complete"') 
    sys.exit(0) 

if __name__ == '__main__': 
    Main() 

Chrome扩展程序被放置在一个地方2个文件目录:

的manifest.json

{ 
    "manifest_version": 2, 

    "background": { 
     "persistent": false, 
     "scripts": [ "bg.js" ] 
    }, 

    "name": "JNLP Fixer", 
    "description": "Handle JNLPs", 
    "version": "1.0", 

    "permissions": [ 
    "downloads", "nativeMessaging" 
    ] 
} 

而且bg.js(编辑根据需要为主机过滤器)

chrome.downloads.onCreated.addListener(function(downloadId) { 
    var expr = /\.jnlp$/; 
    //this is to limit where we apply the auto-launch. 
    //for our use, i only wanted it for internal jnlps. 
    var hostExpr = /(http|https):\/\/internal.company.com\//; 
    if (hostExpr.test(downloadId.url)) { 
     if (downloadId.state == "in_progress") { 
      console.log(downloadId.url); 
      chrome.downloads.cancel(downloadId.id,function() { 
       console.log("cancelled"); 
      }); 
      chrome.runtime.sendNativeMessage("com.hcs.jnlplauncher", 
              {url:downloadId.url}, 
              function(response) 
              { 
        console.log(chrome.runtime.lastError); 
        console.log(response); 
        } 
       ); 
     } 
    } 

}) 

放清单。json和bg.js放在一个文件夹中,并在chrome下以开发人员模式在chrome中加载为Unpacked扩展名。// extensions

从chrome:// extensions页面获取扩展的ID。

接下来是扩展和shell脚本之间的桥梁。

文件:com.hcs.jnlplauncher.json

{ 
    "name": "com.hcs.jnlplauncher", 
    "description": "JNLP Launcher", 
    "path": "/usr/local/bin/jnlp-launcher", 
    "type": "stdio", 
    "allowed_origins": [ 
    "chrome-extension://iacomlhfiphkdfjjjmlgckdkhmkhkibe/" 
    ] 
} 

将这个在 “〜/的.config /谷歌铬/ NativeMessagingHosts”(对于Linux)。看到谷歌的Windows位置。

将您的扩展ID从上一步放入该文件。

确保javaws在路径中。 (该chrome运行)。链接到/ usr/bin是确保最简单的方法。

点击jnlp文件,享受!没有提示,没有ClickToOpen,也没有文件保存在Downloads目录中。

如果有人想把这些都捆绑到一个很好的打包安装程序和/或铬扩展免费。请相信我(克里斯霍尔特 - [email protected])并让我知道。乍看之下,我看不出如何将NativeMessagingHosts作品捆绑到扩展中。也许它必须是2件?这是我在Chrome扩展和NativeMessaging中的第一次冒险。大部分代码都来自API文档和示例,并且可能存在一些错误。

+0

嗨@Chris Holt,太棒了。但我的Chrome还在下载文件;然而,我现在可以在状态栏中点击下载的文件,然后启动javaws,大大改进 - 非常感谢。 – tink 2016-06-14 19:44:55