kubo44
kubo44

Reputation: 63

H2 bundle dependency not found

I use H2 bundle in eclipse RCP application. It uses java implementation like this:

create alias MY_FUNCTION for "com.fun.MyFunctions.myFunction";

where MyFunctions is public class and myFunction is public static method.

It was working for H2 versions 1.3.170 or older, because of following declaration in the MANIFEST.MF:

DynamicImport-Package: *

Newer H2 versions don't have this declaration anymore and therefore I get ClassNotFound exception.

In the git log of the H2 I found following comment (for the commit removing DynamicImport):

Improved OSGi support. H2 now registers itself as a DataSourceFactory service. Fixes issue 365.

Documentation was not very helpful: http://www.h2database.com/html/tutorial.html#osgi

Do you have any idea how can I add my dependency now?

Upvotes: 0

Views: 86

Answers (1)

Tim Ward
Tim Ward

Reputation: 1199

H2 moved to using a DataSourceFactory because it's a much better (and provider independent) way of getting hold of a Driver or DataSource. It's actually not particularly related to the presence of DynamicImport-Package: * The use of a wildcard dynamic import was probably added specifically to address your use case, but it is fundamentally a very poor modularity practice, and can lead to all sorts of issues. For example there's no way to stop H2 from trying to load your function after your bundle is removed.

Assuming that your function isn't too complex you're probably better off registering it as Java source. This is explained in the H2 docs and isn't too complex to do. Effectively you register your alias, but with the Java source marked up in dollar signs:

CREATE ALIAS MY_FUNCTION AS $$
String myFunction(String arg) {

    // Your implementation goes in here

    return arg;
}
$$;

Upvotes: 1

Related Questions