I want to use an H2 database in my Java project, but unfortunately I can’t use any external .jar or .class files. (It’s a build system out of my control and I can only submit source files to it, stupid as that is.) So I thought to simply download the H2 Java sources and add all these Java packages and Java files directly into my project source folder.
However, after doing so I get several build errors in Eclipse for some of the Java files in the H2 code base. For example, the file “org.h2.jdbc.JdbcStatement” has the following errors: “The type JdbcStatement must implement the inherited abstract method Wrapper.unwrap(Class)”. There are also several other errors as well.
So my question is: how can or should I properly add the H2 source files into my Java project?
The sources jar file of H2 is available in the Maven repository, as described in the download section of the docs. The current version is:
http://repo2.maven.org/maven2/com/h2database/h2/1.3.166/h2-1.3.166-sources.jar
You may have to “switch” the source code of H2 to the target Java version however. (This is required because the source code can’t at the same time be used for Java 5 and for Java 6 – as an example the JDBC API in Java 6 has to support the method
ResultSet.updateNClob(int columnIndex, NClob x), but the interfaceNClobis not available in Java 5.) This is the reason why you get the exception “The type JdbcStatement must implement the inherited abstract method Wrapper.unwrap(Class)”.To switch the source code, you can use the build script of H2, or you can use find / replace yourself: to enable Java 6, replace the string
/*## Java 1.6 ##with//## Java 1.6 ##in the source code.