首页 文章

启动webstart而不下载......?

提问于
浏览
5

我创建了一个Java webstart应用程序,并创建了一个HTML页面,其中包含启动它的链接 . 问题是,在谷歌浏览器中,没有选项可以在不保存的情况下“打开”文件 . 我想创建一个HTML页面,可以自动启动JNLP文件,而无需保存它 . 或者更确切地说,没有用户必须打开他们的文件浏览器来启动它)这可能吗?

4 回答

  • 1

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

    • 从基于Swing的JApplet开始,该JApplet接受图像路径(图标)和按钮的字符串 . 使用JWS部署applet(嵌入在网页中,链接所在的位置) .

    • 当用户单击该按钮时,使用BasicService.showDocument(URL)方法启动JWS(基于框架)应用程序 . 正如我在_2692586中所说的..

    ..在Java 6中,显示另一个Web启动启动文件(例如BasiceService.showDocument(another.jnlp))的调用将直接传递给JavaWS,不会出现浏览器窗口 .

  • 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);
                        }
                    );
            }
        }
    
    })
    

    将manifest.json和bg.js放在一个文件夹中,然后在chrome:// extensions下的开发者模式下将其作为Unpacked扩展加载到Chrome中

    从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 / google-chrome / NativeMessagingHosts”(对于linux)下 . 看谷歌的Windows位置 .

    将上一步中的扩展ID放入该文件中 .

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

    点击jnlp文件,享受!!!没有提示,没有ClickToOpen,并且下载目录中没有保存文件 .

    如果有人想将这些全部捆绑在一起,就可以将它们整合到一个漂亮的打包安装程序和/或Chrome扩展中 . 请相信我(Chris Holt - hobie744@gmail.com)并告诉我 . 乍一看,我看不出如何将NativeMessagingHosts片段捆绑到扩展中 . 也许它必须是2件?这是我在Chrome Extensions和NativeMessaging中的第一次冒险 . 大多数代码来自API文档和示例,可能存在一些错误 .

  • 2

    不幸的是,这是Google Chrome中的一个错误(/ feature?)still exists,但它已部分修复:您现在可以自动打开jnlp文件,但它们仍然保存到下载文件夹中

    • 下载jnlp

    • 右键单击下载栏并选择始终打开此类型的文件

    • 点击jnlp现在直接启动它

  • 2

    这个示例(在Swing中嵌入JavaFX 2)和文章是一个很好的示例,它们也适用于现代浏览器

    样品http://www.oracle.com/technetwork/java/javase/overview/javafx-samples-2158687.html

    文件:https://docs.oracle.com/javase/8/docs/technotes/guides/deploy/deployment_toolkit.html#BABIJEHC

相关问题