Java JNLP 文件的本地替代品?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2032491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Local alternative to JNLP file?
提问by Ricket
Try as I might, I can't get a JNLP file to run locally (via a double-click). It seems to be an issue of locating a jar file, even when I specify it relative to the jnlp file. I get the following error:
尽我所能,我无法让 JNLP 文件在本地运行(通过双击)。定位 jar 文件似乎是一个问题,即使我相对于 jnlp 文件指定了它。我收到以下错误:
The field <jar>href has an invalid value: helloworld.jar
字段 <jar>href 具有无效值:helloworld.jar
This happens even when the JNLP file is in the same folder as helloworld.jar. I've done searches and this is a consistent problem especially for people who want to package an application on a CD and use JNLP. The only Sun-provided "solution" is the ability to specify the codebase via command line, but that doesn't really help much. I don't understand why they don't assume or allow the codebase to be "." or "file://." - I tried these sorts of things in the codebase parameter of the jnlp tag (inside the file) and nothing worked.
即使 JNLP 文件与 helloworld.jar 位于同一文件夹中,也会发生这种情况。我已经进行了搜索,这是一个一致的问题,特别是对于想要在 CD 上打包应用程序并使用 JNLP 的人。Sun 提供的唯一“解决方案”是通过命令行指定代码库的能力,但这并没有多大帮助。我不明白为什么他们不假设或允许代码库是“。” 或“文件://”。- 我在 jnlp 标签的代码库参数(文件内部)中尝试了这些东西,但没有任何效果。
It is extremely convenient for me to use a JNLP file because I don't need to worry about platform detection, native libraries, or even the main JOGL jar files; I simply include this line and everything is done for me:
使用 JNLP 文件对我来说非常方便,因为我不需要担心平台检测、本地库,甚至主要的 JOGL jar 文件;我只是简单地包含了这一行,一切都为我完成了:
<extension name="JOGL" href="http://download.java.net/media/jogl/builds/archive/jsr-231-2.0-beta10/webstart/jogl-all-awt.jnlp" />
I'm hoping to find something that can do the same sort of thing. If not, I can manually (or with Ant) grab the JOGL jar files, it's not a big deal; just one of those things that JNLP does for me and I'm really going to miss.
我希望找到可以做同样事情的东西。如果没有,我可以手动(或使用 Ant)抓取 JOGL jar 文件,这没什么大不了的;只是 JNLP 为我做的事情之一,我真的会想念。
What is the best alternative to JNLP files, for me to use locally (i.e. double-click to run)? Is there anything so elegant or do I just need to write a shell script for Linux, a batch file for Windows, and have Ant detect and download the appropriate JOGL jars?
什么是 JNLP 文件的最佳替代品,让我在本地使用(即双击运行)?有没有这么优雅的东西,或者我只需要为 Linux 编写一个 shell 脚本,为 Windows 编写一个批处理文件,并让 Ant 检测并下载适当的 JOGL jars?
采纳答案by Riku Lindblad
I've used a .jnlp file like this to launch Java Web Start software locally
我已经使用这样的 .jnlp 文件在本地启动 Java Web Start 软件
specify the code base like so:
<jnlp spec="1.0+" codebase="file://localhost/X:/path/to/jnlp/" href="software.jnlp">
list resources with relative paths:
<resources> <jar href="lib/software.jar" main="true" /> <jar href="lib/softwareLibrary.jar" main="true" /> ... </resources>
and finally tell Web Start where it can find the software entry point inside the jar marked with
main="true"
:<application-desc main-class="com.example.Main" />
像这样指定代码库:
<jnlp spec="1.0+" codebase="file://localhost/X:/path/to/jnlp/" href="software.jnlp">
列出具有相对路径的资源:
<resources> <jar href="lib/software.jar" main="true" /> <jar href="lib/softwareLibrary.jar" main="true" /> ... </resources>
最后告诉 Web Start 在哪里可以找到标有 jar 的软件入口点
main="true"
:<application-desc main-class="com.example.Main" />
The only thing you need to change when deploying remotely is the codebase parameter.
远程部署时唯一需要更改的是代码库参数。
回答by Daniel Hiller
Use a manifest for your jar. There you can define the main class to start and the required libraries. See the Main-class and Class-path arguments in the manifest specification.
为您的 jar 使用清单。在那里您可以定义要启动的主类和所需的库。请参阅清单规范中的 Main-class 和 Class-path 参数。
回答by Thorbj?rn Ravn Andersen
The JNLP system was improved with Java 6 update 10 (a while back) but it is still quite hard to debug (enabling full tracing in the Java Console, and stepping through the javaws source code.
JNLP 系统在 Java 6 更新 10 中得到了改进(不久前),但它仍然很难调试(在 Java 控制台中启用完整跟踪,并逐步执行 javaws 源代码。
In your situation I would go the extra mile and get it to work. Perhaps you would provide a full JNLP-file showing the problem?
在你的情况下,我会加倍努力让它工作。也许您会提供显示问题的完整 JNLP 文件?
回答by whatnick
JNLP is designed for network launching (specifically http(s)) and without a network the Java implementation must get really confused. Even mature projects like eclipse stick with the .sh,.bat option.
JNLP 是为网络启动(特别是 http(s))而设计的,如果没有网络,Java 实现肯定会很困惑。即使像 eclipse 这样的成熟项目也坚持使用 .sh,.bat 选项。
回答by Daniel De León
Just remove the attributes codebase
and href
from jnlp
tag.
只是删除属性codebase
和href
从jnlp
标签。
<jnlp spec="1.0+">
This is supported since java 1.6u18.
这是从 java 1.6u18 开始支持的。