INIT = RUNSCRIPT和相对路径的问题 [英] problem with INIT=RUNSCRIPT and relative paths

查看:1010
本文介绍了INIT = RUNSCRIPT和相对路径的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用maven约定源路径(src /主要src /测试),我有我的sql脚本在src / main / resources / scripts。

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初始化我的db:

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'

You can use the following url:
"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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆