Hello Alejandro,why do you messing with the SystemClassLoader? I suspect this is the part where the CNF is thrown. If you (even this also should be clerly avoided an only be used whisely) must work with classloader directly. use the one of the Activator (test.persistency.Activator.class.getClassLoader()). When you construct the Datasource directly IMo it is even uneccesary to triger the loadin of the org.h2.jdbcx.JdbcDataSource
JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:~/test");
ds.setUser("sa");
ds.setPassword("sa");
Connection conn = ds.getConnection();
context.registerService(CommandProvider.class.getName(),
service, null);
should be enough. By the way: instead of using OSGi APi directly to fetch/register service you sould consider usind Declarative Service this will prevent you from many headaches. (even if it does not help for your current situation...).
Am 07.02.2014 10:35, schrieb Alejandro Villamarin:
Hello Christoph!Well, I keep on getting NFE with the second approach, editing the MANIFEST as you suggested. Here is my manifest:Manifest-Version: 1.0 Ant-Version: Apache Ant 1.8.1 Created-By: 1.6.0_22-b22 (Sun Microsystems Inc.) Bundle-ManifestVersion: 2 Bundle-Name: test Bundle-SymbolicName: test.persistency Bundle-Version: 0.0.1 Bundle-Activator: test.persistency.Activator Require-Bundle: org.eclipse.core.runtime Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Vendor: Rockefeller Bundle-ClassPath: ., lib/h2-latest.jar The following image depicts the project in the explorer: Inline image 1 This is the snippet that tries to load the H2 class: ClassLoader DBHCL = ClassLoader.getSystemClassLoader(); DBHCL.loadClass("org.h2.jdbcx.JdbcDataSource");Class.forName("org.h2.jdbcx.JdbcDataSource", true, DBHCL).newInstance();System.out.println("Class Loaded"); JdbcDataSource ds = new JdbcDataSource(); ds.setURL("jdbc:h2:~/test"); ds.setUser("sa"); ds.setPassword("sa"); Connection conn = ds.getConnection();context.registerService(CommandProvider.class.getName(), service, null);I'm using OpenJDK 6, altough I tried with version 7 and same problem. I've also attached the project itself, if you want to test it. Thanks for the help! AlejandroOn Fri, Feb 7, 2014 at 9:17 AM, Christoph Läubrich <[email protected] <mailto:[email protected]>> wrote:Hi Alejandro, in fact, it dosen't matter how many bundles are using classes/services from another bundle and the OSGi aproach makes it very easy to e.g. update or manage it. Also maybe in the future you (or a third party lib) might use h2 for other purposes and you will then have lib duplications. You even might see ClassCastExceptions in such scenarios. As you have already seen, fighting the framework makes life harder than neccessary. In general (even though I do not recommend this in this case) when working with eclipse, it should be enough to use the Manifest-Editor and add the jar on the tab "Runtime" in the Classpath section (it must be located inside your Bundle project!). Also make sure the jar is added to your Binary Build (located i the buld tab) or it will not be included in an exported artifact by default. If you still encounter problems, you should provide more details (e.g. MANIFEST, project layout, Runtime you are using to execute your bundle). regards, Christoph Am 06.02.2014 20:48, schrieb Alejandro Villamarin: Hello Christoph, Thanks for your response. I was thinking in throwing the JAR in the plugins folder in Eclipse and the create a listener that waits for the service that the H2 bundle registers and then use it, that would be the "OSGi" way...but I'm not sure that fits my case, since only one bundle is going to access the H2 database, there is no need really for my other bundles to access this db....thus, I think the second scenario fits my needs better...that said, any example on how to setup the bundle classpath in the manifest so it doesn't throw NFE all the time? I've tried everything and is still crashing... Regards, Alejandro
-- 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 http://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/groups/opt_out.
<<image/png>>
