我在jar的resources目录中的fat-jar中嵌入了一个HSQLDB。当我的脚本尝试访问数据库时,它会因缺少.lck
文件而抛出错误。但是,我的印象是jar文件中的DB总是以只读模式访问。
Caused by: org.hsqldb.HsqlException: Database lock acquisition failure: lockFile: org.hsqldb.persist.LockFile@18f6cf91[file =/mnt/c/ctakes/SparkCtakes/jar:file:/mnt/c/ctakes/SparkCtakes/lib/ctakes-assembly-4.0.1.jar!/resources/org/apache/ctakes/dictionary/lookup/fast/sno_rx_16ab/sno_rx_16ab.lck, exists=false, locked=false, valid=false, ] method: openRAF reason: java.io.FileNotFoundException: /mnt/c/ctakes/SparkCtakes/jar:file:/mnt/c/ctakes/SparkCtakes/lib/ctakes-assembly-4.0.1.jar!/resources/org/apache/ctakes/dictionary/lookup/fast/sno_rx_16ab/sno_rx_16ab.lck (No such file or directory)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.persist.LockFile.newLockFileLock(Unknown Source)
at org.hsqldb.persist.Logger.acquireLock(Unknown Source)
at org.hsqldb.persist.Logger.open(Unknown Source)
at org.hsqldb.Database.reopen(Unknown Source)
at org.hsqldb.Database.open(Unknown Source)
at org.hsqldb.DatabaseManager.getDatabase(Unknown Source)
at org.hsqldb.DatabaseManager.newSession(Unknown Source)
... 112 more
我创建包含数据库资源的胖jar的方法是将资源文件夹放在src/main/scala/resources
中,然后使用sbt-assembly
打包所有内容。
答案 0 :(得分:0)
当只读数据库位于Jar文件中时,访问数据库的URL必须是res:
类型的URL。
假设Jar中的顶级目录是org
,URL将如下所示:
jdbc:hsqldb:res:/org/apache/ctakes/dictionary/lookup/fast/sno_rx_16ab/sno_rx_16ab