- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我制作了一个 Java webstart 应用程序,并创建了一个带有启动链接的 HTML 页面。问题是,在谷歌浏览器中,没有选项可以只“打开”一个文件而不保存它。我想制作一个可以自动启动 JNLP 文件而无需保存的 HTML 页面。或者更确切地说,用户无需打开文件资源管理器即可启动它)这可能吗?
最佳答案
在受够了这个问题之后,我围绕扩展编写了自己的工作。
它是在 ubuntu 下编写的,但应该是可移植的(甚至可以通过一些工作/阅读到 win32)。
单击即可启动 jnlp 文件,无需提示或下载。它只是将 jnlp 文件的 url 直接传递给 javaws。没有困惑的下载文件夹,没有额外的点击。
它简单、粗暴且有效。我过滤了 URL,因此它只适用于我自己的内部服务器,这样我就不会不小心启动一些随机的 jnlp 文件。我敢肯定,可以做更多的工作来改进它。按原样使用,无保修等。
文件:
/usr/local/bin/jnlp-launcher
#!/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 个文件:
list .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)。请参阅 google 以获取 Windows 位置。
将上一步中的扩展程序 ID 放入该文件。
确保 javaws 在路径中。 (与 chrome 一起运行)。链接到/usr/bin 是最简单的方法。
单击 jnlp 文件并享受!!!没有提示,没有 ClickToOpen,也没有文件保存在下载目录中。!
如果有人想将这些全部捆绑到一个漂亮的打包安装程序和/或 chrome 扩展程序中,请随意。请相信我 (Chris Holt -- hobie744@gmail.com) 并让我知道。乍一看,我看不出如何将 NativeMessagingHosts 部分捆绑到扩展中。也许它必须是 2 件?这是我在 Chrome 扩展和 NativeMessaging 方面的第一次冒险。大部分代码来自 API 文档和示例,可能存在一些错误。
关于java - 启动 webstart 而不下载...?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11679373/
我正在开发一款使用 LWJGL 的游戏,因此需要特定于每个平台的 native 库。上 this page ,作者展示了如何使用使用 Java Webstart 标记以包含包含适当 native 库的
非常感谢所有愿意花时间阅读的人。 我正在努力制作一个 webstart Swing 1.4.2_12 应用程序以使用 java webstart 1.6.0_29 启动。 场景如下: 所有流量都通过
我的 WebStart 小程序无法在两个浏览器或两个浏览器选项卡/窗口中工作。因此,我不想允许运行我的小程序的多个实例。 有谁知道一种方法可以防止小程序的第二个实例运行或检查我的小程序的一个实例在新的
我习惯于向独立的 Java 应用程序添加日志记录,并使用 log4j 和 sl4j 将日志写入文件。我正在将一些应用程序移动到 Java Web 启动格式,但我不清楚执行日志记录以监视应用程序行为的最
有没有办法反编译java webstart应用程序? 最佳答案 启动应用程序,然后从 Webstart 缓存中获取 JAR。像任何其他 Java 应用程序一样继续反编译。 关于java webstar
我有一个使用 webstart 的 EJB 3.0 项目,我正在尝试将其作为 WAR 部署到 JBoss AS 7.1.1。我可以很好地访问 html 页面,但是当我单击 webstart 链接时,它
我们有一个 webstart 应用程序,在启动后使用 EJB 连接到 jboss 服务器。我们最近将此服务器迁移到 jboss5 并更新了连接到它的 webstart 应用程序。现在我们遇到了一个问题
我有一个 logging.properties 文件,我在运行时加载到我的 java 应用程序中: final InputStream logFileInputStream= this.getClas
我必须通过 Java Webstart 部署 Java 应用程序。 Webstart 下载所需的应用程序 jar 和库 jar,然后在下载完所有内容后,应用程序启动前会有 50 秒的延迟。 直接在计算
我将 Java WebStart 与我正在开发的这个简单应用程序一起使用,我还制作了它,以便它能够检查最新版本的 jar 文件的更新。尽管在运行它时,我收到一条错误消息,指出服务器缺少版本响应。 下面
我正在使用 javaws 在 OS X 10.5.7、Java(TM) SE 运行时环境(内部版本 1.6.0_13-b03-211)中运行应用程序,并且命令行参数似乎在 OS X 中被破坏。我在 L
我需要将动态生成的参数( token )传递给 Web 启动应用程序。问题是,除非应用程序之前被 JWS 缓存,否则参数不会被传递。我试过这样传递它: 并使用 System.getProperty
我有一个在办公室使用的小型 javafx2 应用程序。有些人从 Firefox 运行它,有些人将它作为桌面应用程序运行。 Webstart 很棒。 目前的做法是我在jnlp文件中添加了这个:
这看起来像是一个已解决的老问题,但不幸的是我找不到好的引用资料。我有一个使用 Javaassist 的 Java 应用程序。在我将它升级到 webstart 应用程序之前,它工作正常。现在 Javaa
我有一个带有许多依赖 jar(大约 20 个)的 java webstart 应用程序,它作为独立应用程序在开发环境中快速启动。然而,当它部署在 java webstart 中时,启动时间很慢(1 分
Java Webstart 命令行中有什么选项可以跳过安全检查?这仅用于测试目的。 javaws myfile.jar 最佳答案 我相信 Sun JDK 中有两个未记录的命令行选项:-secure(讽
有没有办法将 Stdin 和 Stdout/Stderr 路由到 java webstart 中的另一个进程?我想做的是让 java webstart 应用程序与桌面上的其他进程进行通信。理想情况下,
我一直在尝试让 webstart 在内存不足时转储到堆转储。 我知道 jmap/jconsole 的做法,但我真正想做的是将选项添加到 jnlp 文件并尝试了以下选项。 j2se version="1
我如何在 java webstart .jnlp 文件中指定我的一些 jar 覆盖 JRE 内置实现?就像常规应用程序上认可的 lib 属性一样。 最佳答案 似乎没有办法在 web start 中定义
如何避免Java webstart 不缓存jar 文件? 在开发中,我想避免在 java webstart 中进行缓存。在我的 lanuch.jnlp 中,如果我每次都更改 jar 版本号,它会强制下
我是一名优秀的程序员,十分优秀!