I have an OSGI bundle which gets to the RESOLVED state, but never reaches the ACTIVE state. When I run my application, this is the stacktrace I am obtaining: http://tny.cz/fa949f16
Afterwards, when I try to start the bundle explicitly through the OSGI console, I get this error:
start 53
gogo: BundleException: The activator rsy.home.mac.sm.schedule.service.win.WinServiceActivator for bundle rsy.home.mac.sm.schedule.service.win is invalid
Notice that in the end of the stacktrace ouput, there's the following message:
!ENTRY org.eclipse.osgi 4 0 2014-03-14 10:52:50.984 !MESSAGE Bundle rsy.home.mac.sm.schedule.service.win_1.0.0 [53] is not active.
Here's the code from WinServiceActivator:
package rsy.home.mac.sm.schedule.service.win;
import java.util.HashMap;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
public class WinServiceActivator implements BundleActivator {
private static BundleContext context;
@Override
public void start(BundleContext context) throws Exception {
ServiceActivator.context = context;
ScheduleService schedServ = new ScheduleService();
schedServ.setTdMapping(new HashMap<String, String>());
schedServ.setHtMapping(new HashMap<String, String>());
schedServ.setDoMapping(new HashMap<String, String>());
context.registerService(ScheduleService.class.getName(),
schedServ, null);
}
@Override
public void stop(BundleContext context) throws Exception {
context.ungetService(context.getServiceReference(ScheduleService.class.getName()));
ServiceActivator.context = null;
}
}
And this is my MANIFEST file:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SM Schedule Query Service
Bundle-SymbolicName: rsy.home.mac.sm.schedule.service.sm;singleton:=true
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Service-Component: OSGI-INF/sm_schedule_service.xml
Require-Bundle: rsy.home.mac.sm.jaxrs.lib;bundle-version="1.0.0",
rsy.home.mac.sm.config;bundle-version="0.1.0",
rsy.home.mac.log,
rsy.home.mac.sm.model;bundle-version="1.0.0",
rsy.home.mac.sm.schedule.service;bundle-version="1.0.0",
rsy.home.mac.sm.sm.scheduletable;bundle-version="1.0.0",
resources;bundle-version="1.0.0",
rsy.home.mac.portal.utilities,
rsy.home.mac.portal.logging;bundle-version="1.0.0",
org.eclipse.xsd;bundle-version="2.7.0",
org.eclipse.osgi
Import-Package: org.osgi.service.http;version="1.2.1"
Bundle-ActivationPolicy: lazy
Bundle-Activator: rsy.home.mac.sm.schedule.service.sm.SmServiceActivator
Export-Package: rsy.home.mac.sm.schedule.service.sm
While googling the error "Activator start error, ClassCastException: xxxx cannot be cast to org.osgi.framework.BundleActivator", I found this:
That error is telling you that you have two copies of the BundleActivator class loaded into your VM somehow. The framework is using one and your bundle is using another.
Do you have any other bundles exporting org.osgi.framework? Where is your bundle getting this package from? If you issue the following command in the Felix shell you can see the wiring:
inspect package requirement <bundle-id>
or shortened to:
inspect p r <bundle-id>
Where <bundle-id> is the ID of your bundle, then you should see from where it is getting org.osgi.framework. If it is not the system bundle (org.apache.felix.framework), then you have an issue.
When I executed the given command, I obtained this output:
org.osgi.framework; version="1.7.0" -> org.eclipse.osgi_3.9.0.v20130410-1557 [0]
Do you think this is the reason why the bundle doesn't start? If so, how can I fix this? Following this comment I found on the internet and the comments and answers from people below, I tried to replace this line in the MANIFEST file:
Import-Package: org.osgi.service.http;version="1.2.1"
by this one:
Import-Package: org.osgi.framework
And I get a whole bunch of errors in the code, whose reason given by Eclipse is:
Multiple markers at this line - Access restriction: The type BundleActivator is not accessible due to restriction on required library rsy.home.mac.sm.jaxrs.lib/lib/org.osgi.core-4.2.0.jar - Access restriction: The type BundleListener is not accessible due to restriction on required library rsy.home.mac.sm.jaxrs.lib/lib/org.osgi.core-4.2.0.jar
I would really appreciate some help on this... Thanks!