无法从部署在 JBoss 服务器上的 EAR 文件内访问只读嵌入式 Derby 数据库

发布于 2024-09-25 09:19:38 字数 6511 浏览 9 评论 0原文

我正在尝试访问只读嵌入式 Derby 数据库。它以 myDB.jar 形式提供。该 jar 有一个 Apache Derby 数据库文件夹 - myDB(log 和 seg0 文件夹以及 service.properties 文件)。当我从带有 main 方法的文件运行时,此代码工作正常。但是,当我将其打包到 EAR 并将其部署到服务器上时,它会出现错误。

该数据库用EAR文件打包并部署在JBoss 5.0.1服务器上。

EAR 包含以下内容: • myWebApp.war • myEjbs.jar • myDB.jar • META-INF/MANIFEST.MF 和 META-INF/application.xml

MANIFEST.MF 的内容: 清单版本:1.0 类路径:myDB.jar

myDB.jar 未在 application.xml 中注册

EJB-JAR即myEjbs.jar具有以下内容: • 德比.属性 • META-INF/MANIFEST.MF 和其他,例如 persistence.xml 等。 MANIFEST.MF 的内容: 清单版本:1.0 类路径:myDB.jar • com.xxx.common.DbUtility.class 具有以下访问数据库的代码:

private static String dbURL = "jdbc:derby:jar:(myDB.jar)";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";

连接 con = DriverManager.getConnection(dbURL+ dbName, 用户, 密码);

然后,com.xxx.ejbs 包中的 EJB 使用该类的输出。

以下是我得到的错误:

信息加载的数据库驱动程序:org.apache.derby.jdbc.EmbeddedDriver

信息 SQLException:无法使用类加载器 BaseClassLoader@127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml} 启动数据库 'jar:(myDB.jar)myDB' ,请参阅下一个异常以了解详细信息。

信息 java.sql.SQLException:无法使用类加载器 BaseClassLoader@127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss- 启动数据库 'jar:(myDB.jar)myDB' service.xml},请参阅下一个异常以了解详细信息。

信息位于 org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(来源未知)

信息 [STDOUT] (http-127.0.0.1-8080-1) 位于 org.apache.derby.impl.jdbc.Util.newEmbedSQLException(来源未知)

信息位于 java.sql.DriverManager.getConnection(DriverManager.java:582)

信息位于 java.sql.DriverManager.getConnection(DriverManager.java:185)

信息引起:java.sql.SQLException:无法使用类加载器 BaseClassLoader@127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf 启动数据库 'jar:(myDB.jar)myDB' /jboss-service.xml},请参阅下一个异常以了解详细信息。

信息位于 org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(来源未知)

信息位于 org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(来源未知)

信息 导致:java.sql.SQLException:Java异常:'myDB.jar(系统找不到指定的文件):java.io.FileNotFoundException'。

信息位于 org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(来源未知)

信息位于 org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(来源未知)

信息位于 org.apache.derby.impl.jdbc.Util.newEmbedSQLException(来源未知)

信息位于 org.apache.derby.impl.jdbc.Util.javaException(来源未知)

INFO Caused by: java.io.FileNotFoundException: myDB.jar (系统找不到指定的文件)

信息位于 java.util.zip.ZipFile.open(本机方法)

信息位于 java.util.zip.ZipFile.(ZipFile.java:114)

信息位于 java.util.zip.ZipFile.(ZipFile.java:131)

信息位于 org.apache.derby.impl.io.JarStorageFactory.doInit(来源未知)

信息位于 org.apache.derby.impl.io.BaseStorageFactory.init(来源未知)


感谢你的回复。我现在已尝试以下操作:

(我)

String path = getClass().getClassLoader().getResource("myDB.jar").getPath();
System.out.println("Path found = " + path);
private static String dbURL = "jdbc:derby:jar:" + "(" + path + ")";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";

连接 con = DriverManager.getConnection(dbURL+dbName, 用户, 密码);

它仍然给出相同的错误。以下是服务器日志。

找到信息路径 = /C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/myDB.jar/

信息加载的数据库驱动程序:org.apache.derby.jdbc.EmbeddedDriver

信息 SQLException:无法使用类加载器 BaseClassLoader@e6c6d7{vfsfile:/ 启动数据库 'jar:(/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/myDB.jar/)myDB' C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml},详细信息请参阅下一个异常。

信息位于 org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(来源未知)

INFO Caused by: java.sql.SQLException: Java异常: 'C:\jboss-5.0.1.GA\server\default\deploy\Main.ear\ myDB.jar (系统找不到指定的路径): java. io.FileNotFoundException'。

信息位于 org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(来源未知)

INFO Caused by: java.io.FileNotFoundException: C:\jboss-5.0.1.GA\server\default\deploy\Main.ear\ myDB.jar (系统找不到指定的路径)

信息位于 java.util.zip.ZipFile.open(本机方法)

信息位于 java.util.zip.ZipFile.(ZipFile.java:114)

信息位于 java.util.zip.ZipFile.(ZipFile.java:131)

信息位于 org.apache.derby.impl.io.JarStorageFactory.doInit(来源未知)


以下是 JBoss 最初加载类时的输出:

BaseClassLoader@a75818{vfszip:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/},策略为 VFSClassLoaderPolicy@88a588{name=vfszip:/C:/jboss-5.0.1.GA /server/default/deploy/Main.ear/ 域=null 根=[MemoryContextHandler@19639558[路径= context=vfsmemory://ak42v-bfhwq-ger46v84-1-ger477uj-20 real=vfsmemory://ak42v-bfhwq- ger46v84-1-ger477uj-20],DelegatingHandler@7111491[path=Main.ear context=file:/C:/jboss-5.0.1.GA/server/default/deploy/ real=file:/C:/jboss- 5.0.1.GA/server/default/deploy/Main.ear],DelegatingHandler@1948811[路径=Main.ear/myEJBs.jar context=文件:/C:/jboss-5.0.1.GA/server/default/部署/真实=文件:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/myEJBs.jar],DelegatingHandler@4545587[路径=Main.ear/myDB.jar上下文=文件: /C:/jboss-5.0.1.GA/server/default/deploy/ real=file:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/ myDB.jar], com .xxx.common、com.xxx.ejb、myDB、myDB.seg0、META-INF、myDB.log,...

所以看起来 myDB.jar 位于类路径中,并且数据库文件夹 myDB 也已加载。

(二)

然后我尝试了以下操作:

private static String dbURL_nfdc = "jdbc:derby:/";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";

连接 con = DriverManager.getConnection(dbURL+dbName, 用户, 密码);

我再次收到错误,但是现在我没有收到 FileNotFoundException:

信息 java.sql.SQLException:未找到数据库“/myDB”。

信息 导致:java.sql.SQLException:未找到数据库“/myDB”。

看起来您已经为我指出了正确的方向,但是,我无法找到此错误的原因。

(三)

我还尝试了以下方法:

private static String dbURL_nfdc = "jdbc:derby:"; (No / )
private static String dbName = "myDB";
private static String user = "";
private static String password = "";

连接 con = DriverManager.getConnection(dbURL+dbName, 用户, 密码);

但是,得到相同的 SQLException。

JBoss 有可能将 myDB 视为 java 包而不是简单的文件夹吗?

以下工作有效:

private static String dbURL_nfdc = "jdbc:derby:classpath:/";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";

连接 con = DriverManager.getConnection(dbURL+dbName, 用户, 密码);

非常感谢您引导我走向正确的方向。感谢您的帮助!

I am trying to access a read-only Embedded Derby database. It is available as myDB.jar. This jar has one folder of the Apache Derby database - myDB (log and seg0 folders and service.properties file). This code works fine when I run from a file with a main method. But, when I package it into EAR and deploy it on server it gives error.

This database is packaged with EAR file and deployed on JBoss 5.0.1 server.

The EAR has following contents:
• myWebApp.war
• myEjbs.jar
• myDB.jar
• META-INF/MANIFEST.MF and META-INF/application.xml

Contents of MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: myDB.jar

myDB.jar is not registered in application.xml

EJB-JAR i.e. myEjbs.jar has the following contents:
• derby.properties
• META-INF/MANIFEST.MF and others such as persistence.xml, etc.
Contents of MANIFEST.MF:
Manifest-Version: 1.0
Class-Path: myDB.jar
• com.xxx.common.DbUtility.class that has the following code accessing the database:

private static String dbURL = "jdbc:derby:jar:(myDB.jar)";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";

Connection con = DriverManager.getConnection(dbURL+ dbName, user, password);

The output of this class is then used by the EJBs in com.xxx.ejbs package.

Following is the error I get:

INFO Loaded database driver: org.apache.derby.jdbc.EmbeddedDriver

INFO SQLException: Failed to start database 'jar:(myDB.jar)myDB' with class loader BaseClassLoader@127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}, see the next exception for details.

INFO java.sql.SQLException: Failed to start database 'jar:(myDB.jar)myDB' with class loader BaseClassLoader@127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}, see the next exception for details.

INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)

INFO [STDOUT] (http-127.0.0.1-8080-1) at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)

INFO at java.sql.DriverManager.getConnection(DriverManager.java:582)

INFO at java.sql.DriverManager.getConnection(DriverManager.java:185)

INFO Caused by: java.sql.SQLException: Failed to start database 'jar:(myDB.jar)myDB' with class loader BaseClassLoader@127627{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}, see the next exception for details.

INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)

INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)

INFO Caused by: java.sql.SQLException: Java exception: 'myDB.jar (The system cannot find the file specified): java.io.FileNotFoundException'.

INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)

INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)

INFO at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)

INFO at org.apache.derby.impl.jdbc.Util.javaException(Unknown Source)

INFO Caused by: java.io.FileNotFoundException: myDB.jar (The system cannot find the file specified)

INFO at java.util.zip.ZipFile.open(Native Method)

INFO at java.util.zip.ZipFile.<init>(ZipFile.java:114)

INFO at java.util.zip.ZipFile.<init>(ZipFile.java:131)

INFO at org.apache.derby.impl.io.JarStorageFactory.doInit(Unknown Source)

INFO at org.apache.derby.impl.io.BaseStorageFactory.init(Unknown Source)

Thank you for your reply. I have now tried the following:

(I)

String path = getClass().getClassLoader().getResource("myDB.jar").getPath();
System.out.println("Path found = " + path);
private static String dbURL = "jdbc:derby:jar:" + "(" + path + ")";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";

Connection con = DriverManager.getConnection(dbURL+dbName, user, password);

It still gives the same error. Following is the server log.

INFO Path found = /C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/myDB.jar/

INFO Loaded database driver: org.apache.derby.jdbc.EmbeddedDriver

INFO SQLException: Failed to start database 'jar:(/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/myDB.jar/)myDB' with class loader BaseClassLoader@e6c6d7{vfsfile:/C:/jboss-5.0.1.GA/server/default/conf/jboss-service.xml}, see the next exception for details.

INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)

INFO Caused by: java.sql.SQLException: Java exception: 'C:\jboss-5.0.1.GA\server\default\deploy\Main.ear\ myDB.jar (The system cannot find the path specified): java.io.FileNotFoundException'.

INFO at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)

INFO Caused by: java.io.FileNotFoundException: C:\jboss-5.0.1.GA\server\default\deploy\Main.ear\ myDB.jar (The system cannot find the path specified)

INFO at java.util.zip.ZipFile.open(Native Method)

INFO at java.util.zip.ZipFile.(ZipFile.java:114)

INFO at java.util.zip.ZipFile.(ZipFile.java:131)

INFO at org.apache.derby.impl.io.JarStorageFactory.doInit(Unknown Source)

Following is the output when classes are being loaded by JBoss initially:

BaseClassLoader@a75818{vfszip:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/} with policy VFSClassLoaderPolicy@88a588{name=vfszip:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/ domain=null roots=[MemoryContextHandler@19639558[path= context=vfsmemory://ak42v-bfhwq-ger46v84-1-ger477uj-20 real=vfsmemory://ak42v-bfhwq-ger46v84-1-ger477uj-20], DelegatingHandler@7111491[path=Main.ear context=file:/C:/jboss-5.0.1.GA/server/default/deploy/ real=file:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear], DelegatingHandler@1948811[path=Main.ear/myEJBs.jar context=file:/C:/jboss-5.0.1.GA/server/default/deploy/ real=file:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/myEJBs.jar], DelegatingHandler@4545587[path=Main.ear/ myDB.jar context=file:/C:/jboss-5.0.1.GA/server/default/deploy/ real=file:/C:/jboss-5.0.1.GA/server/default/deploy/Main.ear/ myDB.jar], com.xxx.common, com.xxx.ejb, myDB, myDB.seg0, META-INF, myDB.log, …

So it looks like the myDB.jar is in the classpath and the database folder myDB is also loaded.

(II)

Then I tried the following:

private static String dbURL_nfdc = "jdbc:derby:/";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";

Connection con = DriverManager.getConnection(dbURL+dbName, user, password);

I again get an error, but, now I do not get the FileNotFoundException:

INFO java.sql.SQLException: Database '/myDB' not found.

INFO Caused by: java.sql.SQLException: Database '/myDB' not found.

Looks like you have pointed me in the right direction, but, I am not able to find the reason for this error.

(III)

I also tried the following:

private static String dbURL_nfdc = "jdbc:derby:"; (No / )
private static String dbName = "myDB";
private static String user = "";
private static String password = "";

Connection con = DriverManager.getConnection(dbURL+dbName, user, password);

But, get the same SQLException.

Is it possible that JBoss is treating myDB as a java package and not a simple file folder?

The following worked:

private static String dbURL_nfdc = "jdbc:derby:classpath:/";
private static String dbName = "myDB";
private static String user = "";
private static String password = "";

Connection con = DriverManager.getConnection(dbURL+dbName, user, password);

Thank you so much for leading me in the right direction. Appreciate your help!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

大海や 2024-10-02 09:19:38

由于您的数据库 jar 位于同一个 EJB Ear 包内,因此我认为它应该位于“类路径中”,因此您应该尝试遵循 http://db.apache.org/derby/docs/10.6/devguide/cdevdvlp24155.html#cdevdvlp24155< /a>.

也就是说,我认为您不想使用“jar”子协议。

或者,如果您要使用“jar”子协议,那么我认为括号内的部分应该是您的 ejb Ear 文件的完整文件系统路径。

Since your database jar is inside your same EJB ear package, I think it is supposed to be "in the classpath", so you should try following the "in the classpath" section of the docs at http://db.apache.org/derby/docs/10.6/devguide/cdevdvlp24155.html#cdevdvlp24155.

That is, I don't think you want to use the "jar" sub-protocol.

Alternatively, if you are going to use the "jar" sub-protocol, then I think that the part inside the parentheses should be the full filesystem path of your ejb ear file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文