有没有办法在Java WebStart的.jnlp文件中的<resources>下获得引用的JAR文件?我以为JNLP API可以帮上忙,但是没有找到任何方法。有任何想法吗?

例:

[...]
<resources>
    <j2se version="1.6.0+" />
    <jar href="../lib/wsfacade.jar"/>
    <jar href="../lib/resources.jar"/>
  </resources>
[...]


例如,我想获取wsfacade.jar的路径,这可能吗?

最佳答案

JNLP API的DownloadService2接口可以为您提供应用程序的资源:

DownloadService2 service = (DownloadService2) ServiceManager.lookup("javax.jnlp.DownloadService2");
ResourceSpec alljars = new ResourceSpec(".*", ".*", DownloadService2.JAR)
ResourceSpec[] results = service.getCachedResources(alljars);

for (ResourceSpec spec : results) {
    System.out.println(spec.getUrl());
}


供参考:


http://download.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/examples.html#DownloadService2
http://download.oracle.com/javase/6/docs/jre/api/javaws/jnlp/javax/jnlp/DownloadService2.html

07-28 01:22
查看更多