How to deactivate current bundle if in its activate method is thrown particular exception?
public void activate(BundleContext bundleContext) {
try{
if(something) throw new Exception();
} catch(Exception e) {
//deactivate bundle...
}
}
I’m assuming that you’re talking about Declarative Service components, in that case, you can just let the activate method throw an exception (perhaps wrapping it inside a runtime exception), in that case the component won’t be activated.
You should realize that the DS runtime might try to activate it more than once, though.
There is a pretty similar question here