1

我正在尝试创建一个 webstart 应用程序。它现在运行,但没有读取我的所有设置。

当我启动 jnlp 文件并尝试使用 Inputstream 读取另一个 jars 资源时,就会出现问题。

我已经验证了我的罐子,它们都使用相同的密钥库。

我有一个名为 Browser 的 jar 试图读取另一个名为 Bone 的 jar。

这就是我在 BoneModule 类中读取设置的方式:

InputStream settingsStream = IOUtil.getInputStream("bone.settings");
            InputStream defaultSettintgsStream = IOUtil
                    .getResourceAsStream("/com/mee/bone/bone.settings", BoneModule.class);
            SimpleProperties storage = new SimpleProperties(settingsStream,
                    new SimpleProperties(defaultSettintgsStream, null).getProperties());
            storage.setStoreFilename("bone.settings");
            boneSettings.addStorage(storage);

我已将我的 jnlp 文件设置为:

 <?xml version="1.0" encoding="utf-8"?>
<jnlp spec="1.0+" codebase="http://ip-adress/lib" href="launch.jnlp">
 <information>
    <title>Bildlabbet</title>
    <vendor>mee</vendor>
    <offline-allowed/>
 </information>
 <security>
 <all-permissions/>
 </security>
 <resources>
    <j2se version="1.7+" initial-heap-size="32m" max-heap-size="128m" />
    <property name="jnlp.versionEnabled" value="false"/>
    $dependencies
</resources>
<application-desc
      name="Bildlabbet"
      main-class="com.mee.browser.BildlabbetBrowser"
      width="300"height="300">
</application-desc>
</jnlp>

我的堆栈跟踪:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mee.browser.Browser.initModuleModel(Browser.java:639)
    at com.mee.browser.Browser.<init>(Browser.java:438)
    at com.mee.browser.BildlabbetBrowser$1.run(BildlabbetBrowser.java:92)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "bone.settings" "read")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkRead(Unknown Source)
    at java.io.File.exists(Unknown Source)
    at com.mee.io.IOUtil.getInputStream(IOUtil.java:143)
    at com.mee.io.IOUtil.getInputStream(IOUtil.java:123)
    at com.mee.bone.BoneModule.getBoneSettings(BoneModule.java:91)
    at com.mee.bone.BoneModule.<init>(BoneModule.java:68)
    ... 21 more

正如您在此处看到的,我无法读取另一个 jar 中的设置文件。我的客户端和浏览器的策略设置是:

grant codebase "file:${jars}" {
  permission java.security.AllPermission;
};

grant codebase "file:/var/www/lib/*" {
permisson java.security.AllPermisson;
};

grant codebase"file:/http://ip-adress/lib/*" {
permisson java.security.AllPermission;
};

grant codebase "file:/home/ubuntu/bildlabbet/lib/*"{
permission java.security.AllPermission;

grant {
permission java.util.PropertyPermission "*", "read, write";
};

grant {
permission java.security.AllPermission;
};

甚至可以这样阅读吗?因为它现在正在本地驱动器上读取我的 jar,因为它是 webstart 所做的。

值得一提的是,我正在从临时目录中读取 jar。我已经尝试调试临时文件夹的文件权限。

如果我从服务器而不是本地读取 jars 资源,这是否已修复?

任何建议都会很好!

谢谢!

4

1 回答 1

0

尝试这个:

grant { permission java.io.FilePermission "/dir/yourfile", "read, write" }

于 2013-12-19T06:28:10.637 回答