java - Initialize H2 in-memory from a file contained in a jar? -
how initialize h2 file contained in jar?
currently getting exception:
testcase(checktest): org.h2.jdbc.jdbcsqlexception: io exception: "java.io.filenotfoundexception: /users/user1/.m2/repository/a/3.10-snapshot/a-snapshot-tests.jar!/h2_db.sql (no such file or directory)"; "file:/users/user1/.m2/repository/a/3.10-snapshot/a-3.10-snapshot-tests.jar!/h2_db.sql"; sql statement:(..)
the file want initialize database (h2_db.sql
) inside jar file a-3.10-snapshot-tests.jar
the code looks like
initsqlfile = getinitsqlfile(); //initsqlfile = "/users/user1/.m2/repository/a/3.10-snapshot/a-snapshot-tests.jar!/h2_db.sql" //initsqlfile file contained ina jar, note "!" url = string.format( "jdbc:h2:mem:%s;mode=postgresql;lock_timeout=500;ifexists=true;init=runscript '%s';db_close_delay=-1;mvcc=true", testsuitname, initsqlfile); // later ... con = drivermanager.getconnection(url, user, passwd);
though problem can worked around relatively easily, wondering if h2 supports initialization file within jar file.
or perhaps elegant workaround, doesn't imply temporary files.
additional info: there method looks resources, if resource found in classpath method returns resource's path. resource's path (/users/user1/.m2/repository/a/3.10-snapshot/a-snapshot-tests.jar!/h2_db.sql
) passed parameter method initializes database.
as documented, file name must start zip:
prefix:
zip:/users/user1/.m2/repository/a/3.10-snapshot/a-snapshot-tests.jar!/h2_db.sql
Comments
Post a Comment