I have a client who is insisting that our database be part of the JAR we
supply. I understand that this is generally not recommended because of the
performance issues of having the DB file ZIP in a compressed JAR. I got
around this by making sure our JAR is not compressed.
In the Eclipse IDE, our JAR accesses the DB file with this code:
String jdbcConnectionString = this.getClass().getResource(
"resources/sort_codes.mv.db").toString();
// tweak the connection code to match h2 requirements
jdbcConnectionString = "jdbc:h2:"+ jdbcConnectionString.replace("jar:file",
"zip").replace(".mv.db", "");
// attempt connection
Connection connection = DriverManager.getConnection(jdbcConnectionString,
USER,PASSWORD);
This works beautifully in the IDE with the final connection string being:
jdbc:h2:file:/Users/bob/Documents/workspace/LabelManager/bin/com/mycompany/sorting/resources/sort_codes
Now let's move to the situation where our JAR is made part of a larger
project. IOW, our JAR (child) is within another runnable JAR (parent).
When we get to the connection attempt in the parent JAR, the
jdbcConnectionString comes back with something like this:
jdbc:h2:
zip:/Users/bob/dev/gs-spring-boot/initial/target/gs-spring-boot-0.1.0.jar!/BOOT-INF
*/lib/Labelmanager-1.0.jar!/com/mycompany/sorting/resource/sort_codes*
where the text in bold is referencing information in our child JAR but now
we have a substantial preface generated by the parent JAR. With this
connection string, the connection fails.
In searching around, I am thinking I need to use getResourceAsStream in the
parent/child configuration. But I'd love someone with more experience to
explain what's going on here.
Thanks in advance...
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.