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

时间:2011-02-02 15:05:15

标签: java jnlp java-web-start

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

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

以下方法不起作用:     javaws -codebase''launch.jnlp     java.net.MalformedURLException:没有协议:''     在java.net.URL。(未知来源)     在java.net.URL。(未知来源)     在java.net.URL。(未知来源)     at com.sun.javaws.Main.parseArgs(Unknown Source)     at com.sun.javaws.Main.continueInSecureThread(Unknown Source)     在com.sun.javaws.Main $ 1.run(未知来源)     在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$1.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$1.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$1.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$1.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

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> 

2 个答案:

答案 0 :(得分:1)

尝试代码库值为..

"file:."

答案 1 :(得分:1)

您的JNLP文件似乎应与JNLPDownloadServlet一起使用。它根据您当前运行应用程序的服务器,使用当前值替换$$name$$codebase百宝箱。 (顺便说一下,您也可以使用$$server来引用当前服务器)

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

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

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

一切顺利。