INIT=RUNSCRIPT 和相对路径的问题 [英] problem with INIT=RUNSCRIPT and relative paths
问题描述
我对源路径(src/main src/test)使用 maven 约定,并且我在 src/main/resources/scripts 中有我的 sql 脚本.
I use maven conventions for source paths (src/main src/test) and i have my sql scripts in src/main/resources/scripts.
我想用 H2 内存运行我的应用程序,我想使用 jdbc url 来初始化我的数据库:
I want to run my app with H2 memory and i'd like to use the jdbc url to initialize my db :
database.url=jdbc:h2:mem:;INIT=RUNSCRIPT FROM 'src/main/resources/scripts/create.sql';
我的问题是这个相对路径 (src/main/...) 不起作用,如果 init=runscript 命令没有目标,H2 不会崩溃.
My problem is that this relative path (src/main/... ) does not work, and that H2 won't crash if the init=runscript command targets nothing.
有人知道我应该使用什么路径来完成这项工作吗?
Does someone know what is the path i should use to make this work ?
谢谢
推荐答案
您可以使用以下网址:"jdbc:h2:mem:sample;INIT=RUNSCRIPT FROM 'classpath:scripts/create.sql'"
有了那个,就可以从类路径运行脚本.所以你可以把它放在 src/main/resources/scripts 或 src/test/resources/scripts 在你的 maven(或其他东西)项目中.
With that one it is possible to run script from classpath. So you can just put it src/main/resources/scripts or src/test/resources/scripts in your maven (or something else) project.
这篇关于INIT=RUNSCRIPT 和相对路径的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!