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

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

问题描述

我尝试从java-webstart下载的jar文件中提取一些文件。
下面的代码被用来定位这个jar文件并启动FileSystem

$ p $ 1 $ final $ ProtectionDomain domain = this.getClass() .getProtectionDomain();
final CodeSource source = domain.getCodeSource();
3最终网址url = source.getLocation();
4最终URI uri = url.toURI();
5路径jarPath = Paths.get(uri);
6
7 FileSystem fs = FileSystems.newFileSystem(jarPath,null);

当jar文件位于本地磁盘上时,工作正常,但在第5行JWS场景,因为

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

 java.nio.file.FileSystemNotFoundException:提供程序http未安装
位于java.nio.file.Paths.get(未知来源)

解决方案


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

这是Sun在Oracle收购之前做出的一项安全决定。他们认为这不是applet或JWS应用程序的业务。知道本地文件系统上资源的位置,所以返回的URI现在总是指向服务器,即使它们被本地缓存,该应用程序。有所有权限安全级别。



重新设计应用程序。这是唯一的实际解决方案。

对于内容迭代Zip或Jar有许多方法,但最简单的方法是包含内容列表在Jar的已知位置,使用 getResource()来找到它,读取它,然后提取每个资源。

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

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

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

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

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?

解决方案

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

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.

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天全站免登陆