如何在Play Framework 2.4中使用相对于项目根目录的路径到H2数据库文件配置? [英] How to use a path relative to project root to H2 db-file configuration with Play Framework 2.4?
问题描述
我们正在开发Play 2.4应用程序(Java API).
We're developing a Play 2.4 application (Java API).
出于开发目的,我们希望使用一个持久性H2数据库,该数据库具有相对于项目根目录的DB文件路径.
For dev purposes, we'd like to use a persistent H2 database with DB file path relative to the project root directory.
In How to use a persistent H2 database in the Play Framework instead of in-memory there was solution for Play 2.0:
db.default.url="jdbc:h2:file:data/db"
但是,在Play 2.4中,这似乎不起作用,但是在底部我收到带有以下异常的错误消息:
However, with Play 2.4 this doesn't seem to work but I get error message with the following exception at the bottom:
Caused by: org.h2.jdbc.JdbcSQLException: A file path that is implicitly
relative to the current working directory is not allowed in the database
URL "jdbc:h2:file:data/db". Use an absolute path, ~/name, ./name, or the
baseDir setting instead. [90011-187]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
...
我可以使用绝对路径和相对于主目录的路径进行连接,如下所示:
I could get connection to work with an absolute path and with a path relative to the home directory, like the following:
db.default.url="jdbc:h2:file:/Users/foo/data/db"
或
db.default.url="jdbc:h2:~/data/db"
但是,有什么方法可以引用项目的根文件夹吗?
However, is there some way to refer to the project root folder?
推荐答案
Ok, I did a little research and found this in the changelog (http://www.h2database.com/html/changelog.html):
禁用了隐式相对路径(系统属性"h2.implicitRelativePath"),因此现在需要将数据库URL jdbc:h2:test编写为jdbc:h2:./test.
Implicit relative paths are disabled (system property "h2.implicitRelativePath"), so that the database URL jdbc:h2:test now needs to be written as jdbc:h2:./test.
从版本1.4.177 Beta开始的H2中,不再允许隐式相对路径.因此,在您的情况下,应使用一个明确的相对路径编写该URL:db.default.url="jdbc:h2:./data/db"
.
In H2 starting from version 1.4.177 Beta, implicit relative paths are not allowed anymore. Therefore, in your case the url should be written with a explicit relative path: db.default.url="jdbc:h2:./data/db"
.
这篇关于如何在Play Framework 2.4中使用相对于项目根目录的路径到H2数据库文件配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!