I have an osgi application which runs on equinox. This is how the bundles are started in the bootstrap class.
String[] equinoxArgs = new String[]{"-console"};
EclipseStarter.setInitialProperties(getInitialProperties());
BundleContext context = EclipseStarter.startup(equinoxArgs, null);
List<URL> urls = getListOfBundleUrls();
for(URL url: urls) {
Bundle bundle = context.installBundle(url.toString());
bundle.start();
}
There is a start method in my application in one of the bundles. This method should be called after all the bundles are started to run the application. When that method is called in the bootstrap class, it gives an error saying some classes are not found in the classpath. Here is the stack trace.
Initial SessionFactory creation failed.org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver com.mysql.jdbc.Driver class not found
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.cc.erp.platform.dbutils.services.BasicDBManager.buildSessionFactory(BasicDBManager.java:26)
at com.cc.erp.platform.dbutils.services.BasicDBManager.<clinit>(BasicDBManager.java:12)
at com.cc.erp.platform.dbutils.DBAgent.getNewCRUDService(DBAgent.java:19)
at com.cc.erp.reload.core.WebService.forQuery(WebService.java:51)
at com.cc.erp.reload.ui.CommandLineUserInterface.<init>(CommandLineUserInterface.java:27)
at com.cc.erp.helius.bootstrap.Bootstrap.launchHelius(Bootstrap.java:41)
at com.cc.erp.helius.bootstrap.Bootstrap.main(Bootstrap.java:22)
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Specified JDBC Driver com.mysql.jdbc.Driver class not found
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:107)
at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89)
Package com.mysql.jdbc is exported in the osgi runtime. But its not not in the bootstrap classpath.I believe this method should be called from the framework itself. Please tell me the best way to do it.
Your bundle install/start loop is an anti-pattern. The problem is that starting a bundle immediately forces it to resolve, but it may fail to resolve because its dependencies are not yet installed (maybe because they come later in the list).
This might then prompt you to work out in advance the correct ordering of installation, but that's the wrong answer as well. You should get the OSGi Framework to work the dependencies for you (that's kind of the point of OSGi!).
So you need to install all of your bundles first before you start any of them. For this you need two loops, e.g.:
List<Bundle> installedBundles = new ArrayList<Bundle>();
for (URL url : urls) {
installedBundles.add(context.installBundle(url.toString()));
}
for (Bundle bundle : installedBundles) {
bundle.start();
}