ChunHao Tang
ChunHao Tang

Reputation: 594

How can I execute osgi command in code

I am using Equinox. I wanna execute osgi command in code.

ex. install bundle command

public void start(BundleContext context) throws Exception {

    String cmd = "install file:///e://testBundle.jar"

    // How can I execute cmd in code?
    ...
}

thanks for help

Upvotes: 2

Views: 1066

Answers (1)

Jérémie B
Jérémie B

Reputation: 11022

You can manage bundles through the BundleContext, or an instance of a Bundle:

  1. BundleContext.installBundle allow you to install a bundle from an URL

  2. You can find a Bundle instance with the BundleContext. See for example BundleContext.getBundles(). On a Bundle instance, you can call start(), stop(), update() or uninstall()

See: BundleContext and Bundle

If you really want to access to a shell and execute commands, Equinox uses Apache Felix Gogo Shell. You should get a reference to a CommandProcessor, create a CommandSession from this processor, and call execute on this session.

@Reference
CommandProcessor commandProcessor;

...

CommandSession commandSession = commandProcessor.createSession(System.in, System.out, System.err);
commandSession.execute("..");

Upvotes: 4

Related Questions