Run webstart without downloading ...?

I created a Java webstart application and created an HTML page with a link to launch it. The problem is that in Google Chrome there is no way to simply "open" a file without saving it. I want to create an HTML page that can automatically run a JNLP file without having to save it. Rather, without the user opening his file explorer to run it. Is it possible?

+5
source share
4 answers

Launch JNLP using the built-in applet deployed via web launch.

  • Start with a Swing-based JApplet that takes an image path (icon) and a string for the button. Deploy the applet (embedded in the webpage where the link will be) using JWS.
  • , BasicService.showDocument(URL) JWS ( ). . .

    .. Java 6+ - (, BasiceService.showDocument(another.jnlp)) JavaWS, .

+2

.

ubuntu, ( win32 /).

jnlp . URL- jnlp javaws. , .

, . URL-, , - jnlp. , . AS-IS, .. ..

:

/USR///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 Unpacked extension chrome chrome://extensions

chrome://extensions.

script.

: 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). . google .

.

, javaws . ( ). /usr/bin - .

jnlp !!! , ClickToOpen Downloads.!

- / , . , (Chris Holt - hobie744@gmail.com) . , , NativeMessagingHosts . , 2 ? Chrome Extensions NativeMessaging. API, , , .

+4

, (/feature?) Google Chrome, , : jnlp, -

  • jnlp
  • right-click on the download bar and select to always open files of this type
  • clicking jnlp now immediately launches it
+2
source

This example (embedding JavaFX 2 in Swing) and articles are a great example, and they also work with modern browsers

sample 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

+1
source

All Articles