2

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?

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Matthias
  • 9,817
  • 14
  • 66
  • 125
  • 3
    *"unfortunately I can't use any external .jar files"* Why in heaven's name not? – T.J. Crowder May 10 '12 at 21:51
  • You need to also add all the sources of ALL of h2's dependencies – Eran Medan May 10 '12 at 21:52
  • See also [*How to access Jar file located within source folders*](http://stackoverflow.com/q/10541765/230513)? – trashgod May 10 '12 at 22:08
  • @T.J.Crowder: see my comment below on your answer – Matthias May 10 '12 at 22:26
  • @EranMedan: ok then I need to find out what these deps are... – Matthias May 10 '12 at 22:26
  • @trashgod: thanks, that's my own question, I asked this one here as well because it seems to be quite an issue to use the H2 jar, as you can see in that other posting :( – Matthias May 10 '12 at 22:26
  • @EranMedan H2 doesn't have any dependencies – Thomas Mueller May 11 '12 at 04:52
  • 1
    @Matthias: I've removed my answer, since it doesn't help you, and edited the question to make it clear only *source* files are allowed. Frankly, a build system that doesn't allow any form of external `.jar` or `.class` file is not fit for purpose. I'd recommend escalating this with whoever is in charge of the build system until you reach a level where someone has some sense. – T.J. Crowder May 11 '12 at 07:26

1 Answers1

2

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 interface NClob is 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.

Thomas Mueller
  • 48,905
  • 14
  • 116
  • 132