java 使用Java web start在命令行通过文件名启动应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4875996/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:26:23  来源:igfitidea点击:

Use Java web start to start application on the command line by the file name

javajnlpjava-web-start

提问by albertkao

I can use Java web start to start my Swing GUI application on the command line by the url with jdk 6 & Windows XP: javaws http://localhost:7001/webstart/myapp/launch.jnlp

我可以使用 Java web start 在命令行上通过 jdk 6 和 Windows XP 的 URL 启动我的 Swing GUI 应用程序:javaws http://localhost:7001/webstart/myapp/launch.jnlp

How to use Java web start to start my Swing GUI application on the command line by the file name?

如何使用 Java web start 在命令行上通过文件名启动我的 Swing GUI 应用程序?

The following ways do not work: javaws -codebase '' launch.jnlp java.net.MalformedURLException: no protocol: '' at java.net.URL.(Unknown Source) at java.net.URL.(Unknown Source) at java.net.URL.(Unknown Source) at com.sun.javaws.Main.parseArgs(Unknown Source) at com.sun.javaws.Main.continueInSecureThread(Unknown Source) at com.sun.javaws.Main$1.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

以下方法不起作用: javaws -codebase '' launch.jnlp java.net.MalformedURLException: no protocol: '' at java.net.URL.(Unknown Source) at java.net.URL.(Unknown Source) at java .net.URL.(Unknown Source) at com.sun.javaws.Main.parseArgs(Unknown Source) at com.sun.javaws.Main.continueInSecureThread(Unknown Source) at com.sun.javaws.Main$1.run(Unknown来源)在 java.lang.Thread.run(未知来源)

javaws -codebase "" launch.jnlp
java.net.MalformedURLException: unknown protocol: c
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at java.net.URL.<init>(Unknown Source)
    at com.sun.javaws.Main.parseArgs(Unknown Source)
    at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
    at com.sun.javaws.Main.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

javaws -codebase "file:." launch.jnlp
com.sun.deploy.net.FailedDownloadException: Unable to load resource: file:./$$name
    at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
    at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
    at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
    at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
    at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
    at com.sun.javaws.Launcher.launch(Unknown Source)
    at com.sun.javaws.Main.launchApp(Unknown Source)
    at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
    at com.sun.javaws.Main.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

javaws -codebase "file:." file://launch.jnlp
CouldNotLoadArgumentException[ Could not load file/URL specified: file://launch.jnlp]
    at com.sun.javaws.Main.launchApp(Unknown Source)
    at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
    at com.sun.javaws.Main.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

javaws file://launch.jnlp 
CouldNotLoadArgumentException[ Could not load file/URL specified: file://launch.jnlp]
    at com.sun.javaws.Main.launchApp(Unknown Source)
    at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
    at com.sun.javaws.Main.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

#The following has no error message, but nothing appear on the computer screen:
javaws -codebase "" -J-Xrunjdwp:transport=dt_socket launch.jnlp
javaws -J-Xdebug -J-Xnoagent -J-Xrunjdwp:transport=dt_socket,server=n,suspend=y launch.jnlp
javaws -codebase "" -J-Xrunjdwp:transport=dt_socket,server=n,suspend=n launch.jnlp
javaws -codebase "" -J-Xrunjdwp:transport=dt_socket,server=y,suspend=n launch.jnlp

The launch.jnlp file is as follows:

launch.jnlp 文件如下:

<?xml version="1.0" encoding="utf-8"?> 

<jnlp spec="1.0+" codebase="$$codebase" href="$$name"> 

  <information> 
    <title>${com.prod.my.myapp.common.client.title}</title> 
    <vendor>I</vendor> 
    <homepage href="http://devzone/english/dev%20template/html_templates/main.asp"/> 
    <description>${com.prod.my.myapp.common.client.description}</description> 
    <description kind="short">${com.prod.my.myapp.common.client.short_description}</description> 
    <icon href="$$context/images/chflag.jpg"/> 
  </information> 

  <security> 
      <all-permissions/> 
  </security> 

  <resources> 

  <java version="1.6.0_05" href="http://java.sun.com/products/autodl/j2se" max-heap-size="256m"/> 

    <!-- myapp Application --> 
    <jar href="myprod.myapp.client.jar"/> 
    <jar href="myprod.reports.jar"/> 

    <!-- TR Client jar --> 
    <jar href="extern.ejb-client.jar"/> 

    <property name="java.naming.factory.initial" value="weblogic.jndi.WLInitialContextFactory"/> 
    <property name="java.naming.provider.url" value="${com.prod.my.myapp.common.client.naming_provider}"/> 
    <property name="weblogic.jndi.enableServerAffinity" value="true" / 

  </resources> 

  <application-desc main-class="com.prod.my.myapp.common.framework.applicationmainwindow.gui.myappAp-plication"/ 

</jnlp> 

回答by Andrew Thompson

Try a codebase value of..

尝试一个代码库值..

"file:."

回答by Jan Zyka

It seems your JNLP file should be used together with the JNLPDownloadServlet. It replaces the $$nameand $$codebasepalceholders with the current values based on the server where you application currently runs. (Btw. you can also use $$serverto refer the current server)

看来您的 JNLP 文件应该与JNLPDownloadServlet一起使用。它根据您的应用程序当前运行的服务器将$$name$$codebase占位符替换为当前值。(顺便说一句,您也可以使用$$server来引用当前服务器)

If you run it locally from disk, you can overwrite the codebaseby setting it on the command line as parameter -codebase. The right value is file:.. You problem is that the $$nameplaceholder is not replaced and it tries do download the <jnlp ... href="$$name">which results to file:.$$nameand since no such file exists it fails.

如果从磁盘本地运行它,则可以codebase通过在命令行上将其设置为参数来覆盖-codebase。正确的值为file:.。你的问题是$$name占位符没有被替换,它会尝试<jnlp ... href="$$name">将结果下载到file:.$$name,因为不存在这样的文件,所以它失败了。

You can either completely omitt the href="$$name"attribute in the <jnlp />tag when running locally or manually change it to the jnlp file name e.g. <jnlp ... href="myApp.jnlp" />.

您可以href="$$name"<jnlp />本地运行时完全省略标记中的属性,也可以手动将其更改为 jnlp 文件名,例如<jnlp ... href="myApp.jnlp" />.

Also remeber if you want to use some local jar stored on you disk and you want to refer it via absolute path you should use this format <jar href="file:c:/myJars/myJar.jar">(forward slashes).

另外请记住,如果您想使用存储在磁盘上的一些本地 jar 并且您想通过绝对路径引用它,您应该使用这种格式<jar href="file:c:/myJars/myJar.jar">(正斜杠)。

All the best.

一切顺利。