Unable to access a read-only Embedded Derby database from within EAR file deployed on JBoss server
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. Co开发者_如何学运维ntents 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!!!
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.
精彩评论