Datanucleus + OSGi (Equinox) gives error No suitable driver found for jdbc:mysql://localhost:3306/jdoosgitest
I am trying to use datanucleus jdo implementation inside the osgi environment but I am constantly getting error : No suitable driver found for jdbc:mysql://localhost:3306/jdoosgitest
I have been following the link http://www.datanucleus.org/servlet/wiki/display/USERS/HOWTO+Use+Datanucleus+with+OSGi+and+Spring+DM
But I don't want to use SpringDM. Firstly because I don't know Spring and I am new to OSGi and JDO also.
Environment Details
DataNucleus Bundles and changes in MANIFEST.MF
datanucleus-api-jdo-3.0.0-m2.jar -- Eclipse-BuddyPolicy=registered
datanucleus-core-3.0.0-m2.jar -- Eclipse-BuddyPolicy=registered
datanucleus-rdbms-3.0.0-m2.jar -- Eclipse-BuddyPolicy=registered
jdo-api-3.0.jar -- Eclipse-BuddyPolicy=registered
Eclipse Bundle And Equinox
org.eclipse.core.contenttype_3.4.1.R35x_v20090826-0451.jar org.eclipse.core.jobs_3.4.100.v20090429-1800.jar org.eclipse.core.runtime_3.5.0.v20090525.jar org.eclipse.equinox.app_1.2.1.R35x_v20091203.jar org.eclipse.equinox.common_3.5.1.R35x_v20090807-1100.jar org.eclipse.equinox.preferences_3.2.301.R35x_v20091117.jar org.eclipse.equinox.registry_3.4.100.v20090520-1800.jar org.eclipse.osgi_3.5.2.R35x_v20100126.jar org.eclipse.osgi.services_3.2.0.v20090520-1800.jar
MyBundle: TestJdoOSGi
Other lib used TestJdoOSGi/lib/mysql-connector-java-5.1.14-bin.jar
TestJdoOSGi/META-INF/MANIFEST.MF --
Eclipse-RegisterBuddy= org.datanucleus.store.rdbms, javax.jdo, org.datanucleus.api.jdo, org.datanucleus
Bundle-ClassPath= bin, lib/mysql-connector-java-5.1.14-bin.jar
The method that gets the PersistenceManager Factory
public PersistenceManagerFactory createPMF()
{
Map defaultProps = new HashMap();
defaultProps.put("javax.jdo.PersistenceManagerFactoryClass", "org.datanucleus.api.jdo.JDOPersistenceManagerFactory");
defaultProps.put("datanucleus.metadata.validate", "false");
defaultProps.put("javax.jdo.option.ConnectionDriverName", "org.gjt.mm.mysql.Driver");
defaultProps.put("javax.jdo.option.ConnectionURL", "jdbc:mysql://localhost:3306/jdoosgitest");
defaultProps.put("javax.jdo.option.ConnectionUserName", "root");
defaultProps.put("javax.jdo.option.ConnectionPassword", "root");
defaultProps.put("javax.jdo.option.Mapping", "mysql");
defaultProps.put("datanucleus.autoCreateSchema", "true");
defaultProps.put("datanucleus.validateTables", "false");
defaultProps.put("datanucleus.validateConstraints", "false");
ClassLoader dirverClassLoader = null;
try {
dirverClassLoader = Activator.bundleContext.getBundle().loadClass("test.jdo.osgi.MyTest").getClassLoader();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
defaultProps.put("datanucleus.开发者_运维知识库primaryClassLoader", dirverClassLoader);
ClassLoader factoryClassLoader = getFactoryClassLoader();
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(defaultProps, factoryClassLoader);
return pmf;
}
private ClassLoader getFactoryClassLoader() {
ClassLoader classloader = null;
Bundle[] bundles = Activator.bundleContext.getBundles();
for (int x = 0; x < bundles.length; x++) {
if ("org.datanucleus.api.jdo".equals(bundles[x].getSymbolicName())) {
try {
classloader = bundles[x].loadClass("org.datanucleus.api.jdo.JDOPersistenceManagerFactory").getClassLoader();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
return classloader;
}
精彩评论