Java 无法从 Netbeans 7.4 启动 derby 数据库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21154400/
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
Unable to start derby database from Netbeans 7.4
提问by Superman9999
I downloaded Netbeans 7.4 and Java 7 Update 51. I get the below error when I try to start Java DB or derby connection from Netbeans. This is on a windows 8 PC. I downloaded the version for windows xp 32 bit at work. It works fine. I am not sure what is missing.
我下载了 Netbeans 7.4 和 Java 7 Update 51。当我尝试从 Netbeans 启动 Java DB 或 derby 连接时出现以下错误。这是在 Windows 8 PC 上。我在工作时下载了适用于 Windows xp 32 位的版本。它工作正常。我不确定缺少什么。
Thu Jan 16 00:48:23 EST 2014 : Security manager installed using the Basic server security policy.
Thu Jan 16 00:48:24 EST 2014 : access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
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 java.lang.SecurityManager.checkListen(SecurityManager.java:1134)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at java.net.ServerSocket.<init>(ServerSocket.java:237)
at javax.net.DefaultServerSocketFactory.createServerSocket(ServerSocketFactory.java:231)
at org.apache.derby.impl.drda.NetworkServerControlImpl.createServerSocket(Unknown Source)
at org.apache.derby.impl.drda.NetworkServerControlImpl.accessSystem.out.println(System.getProperty("java.home"));
0(Unknown Source)
at org.apache.derby.impl.drda.NetworkServerControlImpl.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.derby.impl.drda.NetworkServerControlImpl.blockingStart(Unknown Source)
at org.apache.derby.impl.drda.NetworkServerControlImpl.executeWork(Unknown Source)
at org.apache.derby.drda.NetworkServerControl.main(Unknown Source)
采纳答案by user2060065
This is what I did:
这就是我所做的:
Find out exactly where the java home is by executing this instruction from NetBeans 7.4 :
C:\Program Files\Java\jdk1.7.0_51\jre
This is the output for my case:
C:\Program Files\Java\jdk1.7.0_51\jre\lib\security\java.policy
which is quite important for me, I was modifying another
java.policy
and took no effect and wasted me a couple of hours.For reason of
java.policy
is an unix style file and read-only, I opened and edited it with notepad++ and executed as administrator (under the same java home):grant { permission java.net.SocketPermission "localhost:1527", "listen"; };
Add only these lines into the file after the first grant:
System.out.println(System.getProperty("java.home"));
- Save the file, which is a little tricky for reason of the permission. But if you run notepad++ or any other edit program as administrator, you can solve the problem.
Then try to connect the database from NetBeans, it works for me.
通过从 NetBeans 7.4 执行以下指令,找出 java home 的确切位置:
C:\Program Files\Java\jdk1.7.0_51\jre
这是我的案例的输出:
C:\Program Files\Java\jdk1.7.0_51\jre\lib\security\java.policy
这对我来说非常重要,我正在修改另一个
java.policy
并且没有效果并且浪费了我几个小时。由于
java.policy
是一个unix样式文件并且是只读的,我用notepad++打开并编辑它并以管理员身份执行(在同一个java home下):grant { permission java.net.SocketPermission "localhost:1527", "listen"; };
第一次授权后,仅将这些行添加到文件中:
cd $JAVA_HOME/jre/lib/security
- 保存文件,由于权限原因,这有点棘手。但是,如果您以管理员身份运行 notepad++ 或任何其他编辑程序,则可以解决问题。
然后尝试从 NetBeans 连接数据库,它对我有用。
Good luck.
祝你好运。
回答by Chuk Lee
See http://www.oracle.com/technetwork/java/javase/7u51-relnotes-2085002.htmlfor the description of the "problem". Search other-libs/javadb
有关“问题”的描述,请参见http://www.oracle.com/technetwork/java/javase/7u51-relnotes-2085002.html。搜索其他库/javadb
Depending on your requirement, what I did was go and modify the default security policy
根据您的要求,我所做的是修改默认安全策略
grant codeBase "file:${java.home}}/../db/lib/*" {
permission java.security.AllPermission;
};
Edit java.policy
(make a backup first!)
编辑java.policy
(先备份!)
Add the following
添加以下内容
grant codeBase "file:${java.home}}/../db/lib/*" {
permission java.net.SocketPermission "localhost:1527", "listen,resolve";
};
Note that this is my requirement.
请注意,这是我的要求。
I'm granting every app who uses the u51 JRE the permission to start Derby.
我授予每个使用 u51 JRE 的应用程序启动 Derby 的权限。
EDIT
编辑
The alternative would be to use a less permissive set of permissions like:
另一种方法是使用一组不太宽松的权限,例如:
grant codeBase "file:/Applications/NetBeans/glassfish-4.0/javadb/lib/*" {
permission java.net.SocketPermission "localhost:1527", "listen,resolve";
};
NetBeans, by default, uses the derby version installed with GlassFish. So my permissions look like this on the Mac. It will be similar on Windows, but the path will need to change.
默认情况下,NetBeans 使用与 GlassFish 一起安装的 derby 版本。所以我的权限在 Mac 上是这样的。它在 Windows 上类似,但路径需要更改。
permission java.net.SocketPermission "localhost:1527", "listen,resolve";
回答by user3206735
My solution to this was to reinstall jdk 1.7.45, uninstall netbeans and reinstall it selecting the outdated jdk. Don't know if there is a way to change sdk in NB without reinstalling it but it worked this way.
我对此的解决方案是重新安装 jdk 1.7.45,卸载 netbeans 并选择过时的 jdk 重新安装它。不知道是否有办法在 NB 中更改 sdk 而不重新安装它,但它是这样工作的。
回答by LeoTom
Because the upper measures didn't work I added the following permission to the end of the main permission section:
由于上层措施不起作用,我在主要权限部分的末尾添加了以下权限:
grant{
//List of granted permissions
permission java.net.SocketPermission "localhost:1527", "listen";
}
回答by Patrick W
According to Java? SE Development Kit 7, Update 51 Release Notes
Change in Default Socket Permissions
The default socket permissions assigned to all code including untrusted code have been changed in this release. Previously, all code was able to bind any socket type to any port number greater than or equal to 1024. It is still possible to bind sockets to the ephemeral port range on each system. The exact range of ephemeral ports varies from one operating system to another, but it is typically in the high range (such as from 49152 to 65535). The new restriction is that binding sockets outside of the ephemeral range now requires an explicit permission in the system security policy.
Most applications using client tcp sockets and a security manager will not see any problem, as these typically bind to ephemeral ports anyway. Applications using datagram sockets or server tcp sockets (and a security manager) may encounter security exceptions where none were seen before. If this occurs, users should review whether the port number being requested is expected, and if this is the case, a socket permission grant can be added to the local security policy, to resolve the issue.
默认套接字权限的更改
此版本中已更改分配给所有代码(包括不受信任的代码)的默认套接字权限。以前,所有代码都能够将任何套接字类型绑定到任何大于或等于 1024 的端口号。仍然可以将套接字绑定到每个系统上的临时端口范围。临时端口的确切范围因操作系统而异,但通常在高范围内(例如从 49152 到 65535)。新的限制是绑定临时范围之外的套接字现在需要系统安全策略中的明确许可。
大多数使用客户端 tcp 套接字和安全管理器的应用程序都不会遇到任何问题,因为这些通常无论如何都会绑定到临时端口。使用数据报套接字或服务器 tcp 套接字(和安全管理器)的应用程序可能会遇到以前从未见过的安全异常。如果发生这种情况,用户应该检查所请求的端口号是否符合预期,如果是这种情况,可以将套接字权限授予添加到本地安全策略中以解决问题。
This means that you have to explicity set the permissions for your application to be able to access the ports range between 1025and 49151. You can therefore grant this permission by appending this line in the list of permissions granted:
这意味着您必须明确设置应用程序的权限才能访问1025和49151之间的端口范围。因此,您可以通过在授予的权限列表中附加以下行来授予此权限:
Visit your Java Home Directory and access your policy file at $JAVA_HOME/jre/lib/security/java.policy
and make the following changes.
访问您的 Java 主目录并访问您的策略文件$JAVA_HOME/jre/lib/security/java.policy
并进行以下更改。
grant codeBase "file:/-" {
permission java.security.AllPermission;
};
回答by Gianluigi Pierini
The problem is the Java 7u51, it have a bug that affect Derby and other programs and libraries, I suggest to install the Java 7u45
问题是Java 7u51,它有一个影响Derby和其他程序和库的错误,我建议安装Java 7u45
回答by Alejandro Hdez. Angeles
Well, one alternative is to change the port JavaDB listens to, to be now in the high range (such as from 49152 to 65535). Go to Window->Services, then right click Java DB and in "Java DB Properties Dialog" goto to "Database Location", which in my system is "C:\Users\ahernandeza.netbeans-derby" In that directory edit or create the file derby.properties, and add/edit the line: derby.drda.portNumber=XXXX Where XXXX is the new port, in my case i put 51527 and worked just fine.
好吧,一种替代方法是将 JavaDB 侦听的端口更改为现在处于高范围内(例如从 49152 到 65535)。转到窗口-> 服务,然后右键单击 Java DB 并在“Java DB 属性对话框”中转到“数据库位置”,在我的系统中为“C:\Users\ahernandeza.netbeans-derby” 在该目录中编辑或创建文件 derby.properties,并添加/编辑该行: derby.drda.portNumber=XXXX 其中 XXXX 是新端口,在我的情况下,我放置了 51527 并且工作得很好。
EDIT At fisrt glance it worked, the service started just fine, but when creating or starting a database in NB, i got the error Unable to connect. CAnnot establish a connection to jdbc:derby://localhost:1527/sample Although i changed the pprt to 51527, it tries to connect to 1527
编辑乍一看它工作正常,服务启动得很好,但是在 NB 中创建或启动数据库时,我收到错误无法连接。无法建立到 jdbc:derby://localhost:1527/sample 的连接虽然我把 pprt 改成了 51527,但它试图连接到 1527
回答by user230146
I got a bit fed up with Oracle's approach to security lately. They seem to be trying to protect us from ourselves in ways that would be more appropriate to naive users than programmers. My view is that the code I put on my own machine should be able to do whatever it needs to. It's my fault if I put code there that does bad things. Clearly not a universally reliable perspective, but it's worked for me for about 35 years. On that basis, I add this to my /lib/security/java.policy file:
我最近有点厌倦了 Oracle 的安全方法。他们似乎试图以比程序员更适合幼稚用户的方式保护我们免受自己的伤害。我的观点是,我放在自己机器上的代码应该能够做它需要做的任何事情。如果我把代码放在那里做坏事,那是我的错。显然不是一个普遍可靠的观点,但它对我有用大约 35 年。在此基础上,我将其添加到我的 /lib/security/java.policy 文件中:
file=`find $(dirname $(readlink -f $(which java)))/.. -iname 'java.policy'`; grep 1527 $file || sudo sed -i '0,/"listen"/{s/"listen".*/##代码##\n\tpermission java.net.SocketPermission "localhost:1527", "listen";/}' $file
cat $file
note that the file:/- matches any file on the system, and the grant block says, in essence, "if the class is loaded from this file system, then trust it".
请注意 file:/- 匹配系统上的任何文件,并且授权块实质上表示“如果该类是从该文件系统加载的,则信任它”。
回答by user3381021
This was doing my head in for a bit until I stumbled across the following in the NetBeans wiki
这让我有点头疼,直到我在 NetBeans wiki 中偶然发现以下内容
JavaDB grant permissions
How to grant permissions for Java DB / How to start Java DB
Related to issue #239962
JDK 7u51 comes with some security improvements which are causing problems with starting Java DB on this Java version.
When you try to start DB from NetBeans you will probably get the Exception:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
The same exception you will get while starting using script /db/bin/startNetworkServer
Because there is no suitable way to fix it on the NetBeans side and this should be fixed on the side of the Java DB.
There are several ways how to deal with this problem. I will mention only the easiest way. You have to start DB manually from command line.
? Start Java DB with -noSecurityManager argument.
(JDK 7u51 location)/db/bin/startNetworkServer -noSecurityManager
JavaDB 授予权限
如何授予 Java DB 权限/如何启动 Java DB
与问题 #239962 相关
JDK 7u51 附带了一些安全改进,这会导致在此 Java 版本上启动 Java DB 时出现问题。
当您尝试从 NetBeans 启动 DB 时,您可能会遇到异常:
java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
开始使用脚本 /db/bin/startNetworkServer 时会遇到相同的异常
因为在 NetBeans 端没有合适的方法来修复它,这应该在 Java DB 端修复。
有几种方法可以处理这个问题。我只会提到最简单的方法。您必须从命令行手动启动数据库。
? 使用 -noSecurityManager 参数启动 Java DB。
(JDK 7u51 位置)/db/bin/startNetworkServer -noSecurityManager
Although it's not exactly a solution it is usable as a quick workaround.
虽然它不是一个完全的解决方案,但它可以作为一种快速的解决方法。
回答by test30
If linux, then
如果是linux的话
##代码##it automatically finds your java and changes permissions
它会自动找到您的 java 并更改权限