为什么在浏览器中获取java.lang.reflect.InvocationTargetException,但不能在eclipse小程序查看器中? [英] Why do I get java.lang.reflect.InvocationTargetException in browser but not in eclipse applet viewer?

查看:319
本文介绍了为什么在浏览器中获取java.lang.reflect.InvocationTargetException,但不能在eclipse小程序查看器中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所示:为什么我会在浏览器中获取java.lang.reflect.InvocationTargetException,但不能在eclipse小程序查看器中?当我运行我的小程序(是的,我知道小程序已经过时)在浏览器中使用html加载它,我得到java.lang.reflect.InvocationTargetException错误。我读到,当HTML正在尝试加载不是applet的东西时,会发生这种情况,但是当我将它作为applet中的applet运行时,它会起作用(带来eclipse的java applet查看器,并且完美的...这是什么stumps me) 。这是堆栈跟踪:

Just like the title says: Why do I get java.lang.reflect.InvocationTargetException in browser but not in eclipse applet viewer? When I run my applet (yes, i know applets are outdated) in the browser using html to load it, i get the java.lang.reflect.InvocationTargetException error. I read that this happens when the HTML is trying to load something that is not an applet, but it works when I run it as an applet in eclipse (brings up eclipse java applet viewer and works perfect...that is what stumps me). Here is the stack trace:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.runOnEDTAndWait(Unknown Source)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at com.sun.deploy.uitoolkit.impl.awt.OldPluginAWTUtil.invokeAndWait(Unknown Source)
    ... 5 more
Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "hq.gif" "read")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
    at java.security.AccessController.checkPermission(AccessController.java:559)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at sun.plugin2.applet.AWTAppletSecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
    at sun.awt.SunToolkit.getImageFromHash(SunToolkit.java:774)
    at sun.awt.SunToolkit.getImage(SunToolkit.java:790)
    at sun.lwawt.macosx.LWCToolkit.getImage(LWCToolkit.java:471)
    at javax.swing.ImageIcon.<init>(ImageIcon.java:147)
    at javax.swing.ImageIcon.<init>(ImageIcon.java:174)
    at Application.Game.<init>(Game.java:97)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at java.lang.Class.newInstance(Class.java:374)
    at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:302)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
    at java.awt.EventQueue.access$200(EventQueue.java:103)
    at java.awt.EventQueue$3.run(EventQueue.java:694)
    at java.awt.EventQueue$3.run(EventQueue.java:692)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:708)
    at java.awt.EventQueue$4.run(EventQueue.java:706)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

我的文件结构如下:

index.html
java.policy.applet
hq.gif
b.gif
k.gif
Application (this is the package)/
     Game.java
     Game.class
     ETC

我的java.policy.applet



My java.policy.applet

grant {
  permission java.security.AllPermission;
};


推荐答案

InvocationtargetException is a generic one. The actual exception is 




导致:java.security.AccessControlException:access否认
(java.io.FilePermissionhq.gifread)

Caused by: java.security.AccessControlException: access denied ("java.io.FilePermission" "hq.gif" "read")

除了签名的jar之外,您还需要运行applet的管理权限。

What I assume is, you would need admin priviledges while running the applet in addition to the signed jar.

可以结合以下代码,如 here

Can you incorporate the following code, as described here

AccessController.doPrivileged(new PrivilegedAction() {
    public Object run() {
        // perform the security-sensitive operation here
        return null;
    }
});

这篇关于为什么在浏览器中获取java.lang.reflect.InvocationTargetException,但不能在eclipse小程序查看器中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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