Assuming you have a file to download, you can install the package as:
void install( BundleContext context, File file) throws Exception { Bundle b = context.installBundle( file.toURI().toString() ); b.start(); }
And you can delete it (if the file is gone):
void uninstall( BundleContext context, File file) throws Exception { Bundle b = context.getBundle( file.toURI().toString() ); b.uninstall(); }
You get the BundleContext from the Activator component or Declarative services to be activated. These are recommended methods, but in severe cases you can also use:
BundleContext context = FrameworkUtil.getBundle( this.getClass() ).getBundleContext();
Although it is convenient, it bypasses some mechanism that you might want to use in the future, so it is better to use the context in the recommended form
source share