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

走远了吗. 提交于 2020-02-05 08:57:08

问题


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

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

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: 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

The launch.jnlp file is as follows:

<?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> 

回答1:


Try a codebase value of..

"file:."



回答2:


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

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

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" />.

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

All the best.



来源:https://stackoverflow.com/questions/4875996/use-java-web-start-to-start-application-on-the-command-line-by-the-file-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!