Java 错误:“您的安全设置已阻止本地应用程序运行”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16196425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 05:43:57  来源:igfitidea点击:

Java Error: "Your security settings have blocked a local application from running"

javasecurityapplet

提问by user2279697

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

我正在尝试从我的浏览器(Chrome)运行这个用 Java 编写的简单 HelloWorld 代码:

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 HTMLcode that runs the applet is:

我用NetBeans编译它,然后我创建了一个 WebApplication 项目。运行小程序的HTML代码是:

<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:

如果从 NetBeans 运行小程序,它就可以工作。但是当我通过双击运行 HTML 代码时,浏览器会弹出以下消息:

Your security settings have blocked a local application from running.

您的安全设置已阻止本地应用程序运行。

I tried with Internet Explorer and Firefox but nothing.

我尝试过 Internet Explorer 和 Firefox,但没有。

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

此消息在 Java 上次更新后开始出现。问题出在哪儿?

回答by Pradeep Pati

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 Oraclefor that.

Java 小程序确实会产生安全风险,因此在大多数现代浏览器中都被禁用。您必须降低安全性才能运行它。Oracle为此提供了指南

回答by Andrew Thompson

After reading Java 7 Update 21 Security Improvements in Detail mention..

阅读Java 7 Update 21 Security Improvements in Detail 后提到..

With the introduced changes it is most likely that no end-user is able to run your application when they are either self-signed or unsigned.

通过引入的更改,很可能没有最终用户能够在自签名或未签名时运行您的应用程序。

..I was wondering how this would go for loose class files - the 'simplest' applets of all.

..我想知道这对于松散的类文件会如何处理——“最简单”的小程序。

Local file system

本地文件系统

Dialog: Your security settings have blocked a local application from running
Your security settings have blocked a local application from running

对话框:您的安全设置已阻止本地应用程序运行
您的安全设置已阻止本地应用程序运行

That is the dialog seen for an applet consisting of loose class files being loaded off the local file systemwhen the JRE is set to the default 'High' security setting.

这是当 JRE 设置为默认的“高”安全设置时,由从本地文件系统加载的松散类文件组成的小程序的对话框。



Note that a slight quirk of the JRE only produced that on point 3 of.

请注意,JRE 的一个小怪癖只产生了第 3 点。

  1. Load the applet page to see a broken applet symbol that leads to an empty console.
    Open the Java settings and set the level to Medium.
    Close browser & Java settings.
  2. Load the applet page to see the applet.
    Open the Java settings and set the level to High.
    Close browser & Java settings.
  3. Load the applet page to see a broken applet symbol & the above dialog.
  1. 加载小程序页面以查看导致空控制台的损坏小程序符号。
    打开 Java 设置并将级别设置为Medium
    关闭浏览器和 Java 设置。
  2. 加载小程序页面以查看小程序。
    打开 Java 设置并将级别设置为High
    关闭浏览器和 Java 设置。
  3. 加载小程序页面以查看损坏的小程序符号和上面的对话框。

Internet

互联网

If you load the simple applet (loose class file) seen at this resizable applet demooff the internet- which boasts an appletelement of:

如果您从Internet 上加载在这个可调整大小的小程序演示中看到的简单小程序(松散的类文件)- 它拥有以下元素:applet

<applet
    code="PlafChanger.class"
    codebase="."
    alt="Pluggable Look'n'Feel Changer appears here if Java is enabled"
    width='100%'
    height='250'>
<p>Pluggable Look'n'Feel Changer appears here in a Java capable browser.</p>
</applet>

It also seems to load successfully. Implying that:-

它似乎也成功加载。暗示:-

Applets loaded from the local file system are now subject to a stricter security sandbox than those loaded from the internet or a local server.

从本地文件系统加载的小程序现在受到比从 Internet 或本地服务器加载的更严格的安全沙箱的约束。

Security settings descriptions

安全设置说明

As of Java 7 update 51.

从 Java 7 更新 51 开始。

  • Very High: Most secure setting - Only Java applications identified by a non-expired certificate from a trusted authority will be allowed to run.
  • High (minimum recommended): Java applications identified by a certificate from a trusted authority will be allowed to run.
  • Medium- All Java applications will be allowed to run after presenting a security prompt.
  • 非常高最安全的设置 - 仅允许运行由来自受信任机构的未过期证书标识的 Java 应用程序。
  • 高(推荐最低值)允许运行由受信任机构颁发的证书标识的 Java 应用程序。
  • -在出现安全提示后,所有 Java 应用程序都将被允许运行。

回答by rockstar

I faced the same issue today, and I was able to fix the issue by changing the security settings on the Java Control Panel from HIGHto MEDIUM.

我今天遇到了同样的问题,我能够通过将 Java 控制面板上的安全设置从HIGH更改为MEDIUM.

Well, setting the Java Security Setting to MEDIUM permanently is not really recommended as this will allow potentialy malicious software to run on your system and not be blocked. So I suggest after running your applet you may want to change back the setting to HIGH.

好吧,真的不建议将 Java 安全设置永久设置为 MEDIUM,因为这将允许潜在的恶意软件在您的系统上运行而不会被阻止。所以我建议在运行你的小程序后,你可能想把设置改回 HIGH。

Location of the Java Control Panel

Java 控制面板的位置

Change the setting of the Control Panel

更改控制面板的设置

回答by Burhan ARAS

  1. Go to Control Panel
  2. Double click on Java
  3. Open the Securitytab
  4. Select Medium
  5. Click on Apply
  6. Restart your web browser
  1. 进入控制面板
  2. 双击Java
  3. 打开安全选项卡
  4. 选择媒介
  5. 点击应用
  6. 重新启动您的网络浏览器

That's it!

就是这样!

enter image description here

在此处输入图片说明

回答by rommer

If you are using Linux, these settings are available using /usr/bin/jcontrol(or your path setting to get the current Java tools). You can also edit the files in ~/.java/deployment/deployment.propertiesto set "deployment.security.level=MEDIUM".

如果您使用的是Linux,则可以使用这些设置/usr/bin/jcontrol(或获取当前 Java 工具的路径设置)。您还可以编辑文件~/.java/deployment/deployment.properties以设置“deployment.security.level=MEDIUM”。

Surprisingly, this information is not readily available from the Oracle web site. I miss java.sun.com...

令人惊讶的是,无法从 Oracle 网站轻松获得此信息。我想念java.sun.com...

回答by Rohit

If you are like me whose Java Control Panel does not show Security sliderunder Security Tab to change security level from High to Medium then follow these instructions: Java known bug: security slider not visible.

如果您像我一样,其 Java 控制面板没有在安全选项卡下显示安全滑块以将安全级别从高更改为中,请按照以下说明操作:Java 已知错误:安全滑块不可见



Symptoms:

症状:

After installation, the checkbox to enable/disable Java and the security level slider do not appear in the Java Control Panel Security tab. This can occur with 7u10 and above.

安装后,启用/禁用 Java 的复选框和安全级别滑块不会出现在 Java 控制面板安全选项卡中。这可能发生在 7u10 及更高版本上。

Cause

原因

This is due to a conflict that Java 7u10 and above have with standalone installations of JavaFX. Example: If Java 7u5 and JavaFX 2.1.1 are installed and if Java is updated to 7u11, the Java Control Panel does not show the checkbox or security slider.

这是由于 Java 7u10 及更高版本与 JavaFX 的独立安装存在冲突。示例:如果安装了 Java 7u5 和 JavaFX 2.1.1 并且 Java 更新为 7u11,则 Java 控制面板不会显示复选框或安全滑块。

Resolution

解析度

It is recommended to uninstall all versions of Java and JavaFX before installing Java 7u10 and above.
Please follow the steps below for resolving this issue.
1. Remove all versions of Java and JavaFX through the Windows Uninstall Control Panel. Instructions on uninstalling Java.
2. Run the Microsoft uninstall utility to repair corrupted registry keys that prevents programs from being completely uninstalled or blocking new installations and updates.
3. Download and install the Windows offline installerpackage.

建议在安装 Java 7u10 及更高版本之前卸载所有版本的 Java 和 JavaFX。
请按照以下步骤解决此问题。
1. 通过 Windows 卸载控制面板删除所有版本的 Java 和 JavaFX。关于卸载 Java 的说明。
2. 运行 Microsoft 卸载实用程序来修复损坏的注册表项,这些注册表项会阻止程序被完全卸载或阻止新的安装和更新。
3. 下载并安装 Windows离线安装程序包。

回答by Pavlo Zvarych

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

如果您没有中等安全级别,那么您应该将您的应用程序添加到例外站点列表Java 控制面板安全选项卡)。

  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 PanelSecuritytab and press the Edit Site List...button. screenshot of Java Control Panel's Security tab

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

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

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

  1. 在浏览器中打开小程序并复制地址栏的内容。 screenshot of applet's address in the address bar
  2. 转至控制面板Java 控制面板安全选项卡,然后按Edit Site List...按钮。 screenshot of Java Control Panel's Security tab

  3. Add按钮,插入您的路径,然后按 Enter。 screenshot of Exception Site List

  4. Continue出现的安全警告。 screenshot of Security Warning - FILE Location alert prompt

  5. 再次打开小程序,不要忘记按Run弹出窗口。 screenshot of Security Warning

回答by Vishal Kanaujia

  • Starting with Java 8, there is no "medium" risk setting in the Security tab under Java

  • You will keep getting this error till you revert to older Java (suggested Java 7, it has hit the end of life though).

  • Install both 32-bit and 64-bit version because browsers are still 32-bit, even on a 64-bit machine, 64-bit OS

  • 从 Java 8 开始,Java 下的 Security 选项卡中没有“中等”风险设置

  • 您将继续收到此错误,直到您恢复到较旧的 Java(建议使用 Java 7,但它已达到使用寿命)。

  • 安装 32 位和 64 位版本,因为浏览器仍然是 32 位,即使在 64 位机器上,64 位操作系统

回答by Timo Riikonen

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

我的问题案例是使用 Java8 在本地运行 portecle.jnlp 文件。

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.jnlpin CMD prompt
  1. 启动程序 --> Java --> 配置 Java...
  2. 转到安全性 --> 编辑站点列表...
  3. 添加http://portecle.sourceforce.net
  4. 在 CMD 提示符下启动javaws portecle.jnlp

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

在第 3 步中,您也可以尝试添加 file:///c:/path/portecle.jnlp,但此添加对我的情况没有帮助。

回答by eaglei22

I am using an older Data Structure and Algs book that comes with Java Applets for practice. So I needed to store and run some applets locally. I am currently running Windows 10 OS with Edge, Chrome, and IE 11.

我正在使用 Java Applets 附带的旧数据结构和算法书进行练习。所以我需要在本地存储和运行一些小程序。我目前正在运行带有 Edge、Chrome 和 IE 11 的 Windows 10 操作系统。

Running applets seem to only be allowed in IE11, and as other have mentioned you have to add the applet to the exception list. My issue was since I am storing these locally, and opening them in IE, it opened with path starting with "C:\..." Adding the full path using, "file///..." like mentioned in one of the other answers didn't work for me.

运行小程序似乎只允许在 IE11 中运行,正如其他人提到的,您必须将小程序添加到例外列表中。我的问题是因为我将这些存储在本地,并在 IE 中打开它们,它以以“C:\...”开头的路径打开使用“file///...”添加完整路径,如其中之一所述其他答案对我不起作用。

The fix: So, I just added(without the quotes), "file:///" to the exception site list and finally got it working. This also allows me to run any applet stored locally, and I do not have to explicitly add an exception for each applet path.

修复:所以,我刚刚添加了(不带引号)“file:///”到例外站点列表中,并最终使其正常工作。这也允许我运行本地存储的任何小程序,而且我不必为每个小程序路径显式添加异常。

I plan to remove the exception from the list once I am done using the programs, and only add it back as necessary.

我计划在使用完这些程序后从列表中删除异常,并仅在必要时将其添加回来。