从 JWS 下载的 jar 文件中提取一些内容 [英] Extract some content from jar-file downloaded with JWS

查看:44
本文介绍了从 JWS 下载的 jar 文件中提取一些内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从使用 java-webstart 下载的 jar 文件中提取一些文件.下面的代码用于定位jar并启动文件系统

im trying to extract some files from a jar-file downloaded using java-webstart. below code was used to locate the jar and initiate the FileSystem

1 final ProtectionDomain domain = this.getClass().getProtectionDomain();
2 final CodeSource source = domain.getCodeSource();
3 final URL url    = source.getLocation();
4 final URI uri    = url.toURI();
5 Path jarPath = Paths.get(uri);
6
7 FileSystem fs = FileSystems.newFileSystem(jarPath, null);

当 jar 文件在本地磁盘上时,这工作正常,但在 JWS 场景中的第 5 行失败,因为

This works fine when the jar-file is on a local disc, but fails at line 5 in the JWS scenario, because the

日志说:url=http://localhost:8080/myjarfile.jar

logs says: url=http://localhost:8080/myjarfile.jar

java.nio.file.FileSystemNotFoundException: Provider "http" not installed
at java.nio.file.Paths.get(Unknown Source)

如果我对 JWS 的理解正确的话,myjarfile.jar 已经被下载到一些缓存中,所以为 http 实现一个 FileSystemProvider 以从 myjarfile.jar 获取一些内容似乎很慢而且很复杂.那么有什么关于如何进行的好主意吗?

If I understand JWS correctly, myjarfile.jar has been downloaded to some cache already, so implementing a FileSystemProvider for http to get some content from myjarfile.jar seems slow and complicated. So any good ideas of how to proceed?

推荐答案

日志显示:url=http://localhost:8080/myjarfile.jar

the logs says: url=http://localhost:8080/myjarfile.jar

这是 Sun 在 Oracle 收购他们之前做出的安全决定.他们认为这与小程序或 JWS 应用程序无关.知道资源在本地文件系统上的位置,因此返回的 URI 现在将始终指向服务器,即使它们在本地缓存&应用程序.具有 all-permissions 安全级别.

That was a security decision made by Sun, before Oracle acquired them. They decided it was no business of applets or JWS apps. to know the location of the resources on the local file-system, so the URI returned will now always point back to the server, even if they are cached locally & the app. has all-permissions security level.

那么有什么关于如何进行的好主意吗?

So any good ideas of how to proceed?

重新设计应用.这是唯一可行的解​​决方案.

Redesign the app. That is the only practical solution.

有多种方法可以为内容迭代 Zip 或 Jar,但最简单的方法是在 Jar 的已知位置包含内容列表,使用 getResource(),阅读它,然后提取每个资源.

There are a number of ways to iterate a Zip or Jar for the content, but the simplest method is to include a list of the content in a known location of the Jar, locate it using getResource(), read it, then extract each resource.

这篇关于从 JWS 下载的 jar 文件中提取一些内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆