来自BasicService API的JNLP:getCodeBase()方法不返回完整的代码库路径

时间:2013-07-11 19:26:42

标签: java javafx-2 jnlp

我的应用程序设置如下:

我有一个托管在服务器上的网页,它有一个动态创建JNLP文件的链接,该文件通过http呈现给用户。然后,JNLP用于启动JavaFX应用程序。

我需要从getCodeBase() API访问BasicService方法,以便在每个用户的计算机上本地保存属性。我创建的JNLP如下:

<?xml version="1.0" encoding="utf-8"?>
<jnlp spec="6.0+" xmlns:jfx="http://javafx.com" codebase="http://myserver.com/downloads">
  <information>
    <title>My App</title>
    <vendor>My Vendor</vendor>
    <description>Application to do something</description>
    <homepage href="http://myserver.com/myapp" />
    <offline-allowed/>
    <shortcut online="true">
      <desktop/>
      <menu submenu="My App"/>
    </shortcut>
  </information>

  <security>
    <all-permissions/>
  </security>
<update check="always"/>
  <resources>
    <j2se version="1.7.0_25+" java-vm-args="-Xmx1024m -Djava.net.preferIPv4Stack=true"    href="http://java.sun.com/products/autodl/j2se"/>
    <property name="myID" value="1" /> 
  </resources>

  <resources>
    <jar href="my-app-0.0.1.jar" download="eager" />
  </resources>

  <application-desc main-class="com.myApp.MyApp"/>

</jnlp>

getCodeBase()方法仅返回/downloads而不是http://myserver.com/downloads。如果有人有任何指示纠正错误,那将是有帮助的。

我用来访问代码库的代码如下:

 try
    {
        persistenceService = (PersistenceService) ServiceManager
            .lookup("javax.jnlp.PersistenceService");
        basicService = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService");
    }
    catch (UnavailableServiceException e)
    {
        persistenceService = null;
        basicService = null;
    }

    if (persistenceService != null
        && basicService != null)
    {

        try
        {
            URL codebase = basicService.getCodeBase();

            System.out.println("code base:" + codebase.getFile() + " path is : " + codebase.getPath());

        catch (Exception e)
        {
            e.printStackTrace();
        }

0 个答案:

没有答案