Java Error: “Your security settings have blocked a

2019-01-04 02:03发布

I'm trying to run this simple HelloWorld code written in Java from my browser (Chrome):

public class HelloWorld extends JApplet {
public void init() {
    try {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                JLabel lbl = new JLabel("Hello World");
                add(lbl);
            }
        });
    }
    catch (Exception e) {
        System.err.println("createGUI didn't complete successfully");
    }
}

I compiled it with NetBeans, and then I created a WebApplication project. The HTML code that runs the applet is:

<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <p><applet code="HelloWorld" archive="applet_HelloWorld.jar"  width="590" height="530"></applet></p>
    </body>
</html>

If run the applet from NetBeans it works. But when I run the HTML code by double clicking it, the following message pops up from the browser:

Your security settings have blocked a local application from running.

I tried with Internet Explorer and Firefox but nothing.

This message started to appear after the last update of Java. Where is the problem?

9条回答
The star\"
2楼-- · 2019-01-04 02:31

My problem case was to run portecle.jnlp file locally using Java8.

What worked for me was

  1. Start Programs --> Java --> Configure Java...
  2. Go to Security --> Edit Site List...
  3. Add http://portecle.sourceforce.net
  4. Start javaws portecle.jnlp in CMD prompt

On step 3, you might try also to add file:///c:/path/portecle.jnlp, but this addition didn't help with my case.

查看更多
走好不送
3楼-- · 2019-01-04 02:33

Java applets do create a security risk, hence are disabled in most modern browsers. You have to lower the security to run it. There is a guide by Oracle for that.

查看更多
在下西门庆
4楼-- · 2019-01-04 02:34

If you have no Medium security level, then you should add your application to the Exception Site List (Java Control PanelSecurity tab).

  1. Open your applet in a browser and copy the contents of your address bar. screenshot of applet's address in the address bar
  2. Go to Control PanelJava Control PanelSecurity tab and press the Edit Site List... button. screenshot of Java Control Panel's Security tab

  3. Press the Add button, insert your path and press Enter. screenshot of Exception Site List

  4. Press Continue on the security warning that appears. screenshot of Security Warning - FILE Location alert prompt

  5. Open the applet again and don't forget to press Run on the pop-up window. screenshot of Security Warning

查看更多
登录 后发表回答