我试图用Eclipse中的Cloud SQL数据库连接创建一个appengine应用程序,并且在尝试运行该应用程序时遇到java.security.AccessControlException访问被拒绝错误。

我正在使用Google Appengine插件的1.9.17版本和Eclipse的Google插件的版本4.4。

我的代码基于https://cloud.google.com/appengine/docs/java/cloud-sql/中概述的方法

我尝试使用多种不同的方法来运行该应用程序,但这没有区别。


在Eclipse中使用AppEngine服务器-启动
Appengine服务器
使用Maven appengine:devserver目标运行-该appengine正确启动,尝试加载http://localhost:8080/guestbook.jsp时发生错误


代码提取-guestbook.jsp

if (SystemProperty.environment.value() ==
     SystemProperty.Environment.Value.Production) {
     Class.forName("com.mysql.jdbc.GoogleDriver");
     url = "jdbc:google:mysql://instance:datastore/guestbook";
} else {
     Class.forName("com.mysql.jdbc.Driver");
     url = "jdbc:mysql://localhost:port/guestbook";
}


代码提取-GuestbookServlet.java

try {
  if (SystemProperty.environment.value() ==
      SystemProperty.Environment.Value.Production) {
    Class.forName("com.mysql.jdbc.GoogleDriver");
    url = "jdbc:google:mysql://instance:datastore/guestbook";
  } else {
    Class.forName("com.mysql.jdbc.Driver");
    url = "jdbc:mysql://localhost:port/guestbook";
  }
} catch (Exception e) {
  e.printStackTrace();
  return;
}


错误

[INFO] java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun.jdbc.odbc")
[INFO]     at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
[INFO]     at java.security.AccessController.checkPermission(AccessController.java:559)
[INFO]     at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
[INFO]     at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:429)
[INFO]     at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1525)
[INFO]     at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:114)
[INFO]     at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
[INFO]     at java.lang.Class.forName0(Native Method)
[INFO]     at java.lang.Class.forName(Class.java:270)
[INFO]     at java.sql.DriverManager.isDriverAllowed(DriverManager.java:463)
[INFO]     at java.sql.DriverManager.getConnection(DriverManager.java:568)
[INFO]     at java.sql.DriverManager.getConnection(DriverManager.java:215)
[INFO]     at org.apache.jsp.guestbook_jsp._jspService(guestbook_jsp.java:77)
[INFO]     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
[INFO]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
[INFO]     at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
[INFO]     at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
[INFO]     at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
[INFO]     at com.google.appengine.tools.development.PrivilegedJspServlet.access$101(PrivilegedJspServlet.java:23)
[INFO]     at com.google.appengine.tools.development.PrivilegedJspServlet$2.run(PrivilegedJspServlet.java:61)
[INFO]     at java.security.AccessController.doPrivileged(Native Method)
[INFO]     at com.google.appengine.tools.development.PrivilegedJspServlet.service(PrivilegedJspServlet.java:58)
[INFO]     at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
[INFO]     at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
[INFO]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
[INFO]     at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
[INFO]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]     at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:127)
[INFO]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]     at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
[INFO]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]     at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:63)
[INFO]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]     at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
[INFO]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]     at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
[INFO]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]     at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectRequest(DevAppServerModulesFilter.java:366)
[INFO]     at com.google.appengine.tools.development.DevAppServerModulesFilter.doDirectModuleRequest(DevAppServerModulesFilter.java:349)
[INFO]     at com.google.appengine.tools.development.DevAppServerModulesFilter.doFilter(DevAppServerModulesFilter.java:116)
[INFO]     at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
[INFO]     at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
[INFO]     at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
[INFO]     at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
[INFO]     at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
[INFO]     at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
[INFO]     at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:98)
[INFO]     at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO]     at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:491)
[INFO]     at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
[INFO]     at org.mortbay.jetty.Server.handle(Server.java:326)
[INFO]     at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
[INFO]     at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
[INFO]     at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:547)
[INFO]     at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
[INFO]     at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
[INFO]     at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
[INFO]     at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

最佳答案

这就是它为我工作的方式。
我删除了WEB-INF \ lib文件夹中手动存在的与appengine相关的jar文件。
在构建路径中,我将AppEngine SDK添加为库依赖项。

这为我解决了这个问题。

猜猜问题出在将SDK和单个jar都添加到构建路径时,冲突的jar!

关于java - 尝试从Eclipse运行AppEngine Cloud SQL应用程序时访问被拒绝错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28253230/

10-13 00:55