简体   繁体   中英

Java applet permission denied, security exception

I started learning Java a few weeks ago and now I am in the process of creating a japplet game.

I am using Mac os x and whenever I try to run the applet in the browser I get the following exception

java.lang.SecurityException: Permission denied:

How can I fix this so the JApplet would run? The files are all on local and I'm running the JApplet locally in the browser.

The following the is html code

<html>
<head>
    <title>Java Game!</title>
</head>
<body>

    <applet code="/local/path/to/MainApplet.class"
            width=500
            height=500>
    </applet>

</body>
</html>

UPDATE:

The following is the full console output:

Java.lang.SecurityException: Permission denied:
 file:/path/to/MainApplet.class
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Applet2ClassLoader.java:209)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:201)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
    at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:678)
    at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3045)
    at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
    at java.lang.Thread.run(Thread.java:680)
Exception: java.lang.SecurityException: Permission denied: file:/path/to/MainApplet.class

UPDATE #2

I tried the same code in Windows and there was no problem at all. It's only on Mac that's giving this exception, any ideas?

Since the applets are components that are provided from the Internet, the security framework of Java requieres that you must sign the applet if it will access to locar resources like write or read from hard disk.

For sign the applet you can check the following link: http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM