problem with INIT=RUNSCRIPT and relative paths

JavaHibernateMaven 2ConfigurationH2

Java Problem Overview


I use maven conventions for source paths (src/main src/test) and i have my sql scripts in src/main/resources/scripts.

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';

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 ?

Thanks

Java Solutions


Solution 1 - Java

You can use the following url:
"jdbc:h2:mem:sample;INIT=RUNSCRIPT FROM 'classpath:scripts/create.sql'"

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.

Solution 2 - Java

I'd suggest trying to use an absolute path for starters, just to check everything works. Afterwards, check your classpath. For example, bin/main/resources/scripts/create.sql, assuming bin is where your classes are compiled, and is on your classpath.

Since src, where your source lives, usually isn't on the classpath, this could be the source of your problem.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMaxime ARNSTAMMView Question on Stackoverflow
Solution 1 - JavaviktortnkView Answer on Stackoverflow
Solution 2 - JavadariooView Answer on Stackoverflow