简体   繁体   中英

How to run an osgi module from the command line?

I am trying to run an OSGI module from the command line with the following command:

java -jar target/module.jar -console

However I always get

no main manifest attribute, in target/module.jar

When I extraxct the jar file the MANIFEST.MF is there?

Which manifest did I forget?

You can not simply run a bundle by itself. A bundle needs to run inside an OSGi framework. So you could for example download Apache felix and put your bundle into the felix directory that picks up bundles to load. In this case you would start felix and felix would then load your bundle.

What Peter proposes is to define your set of bundles and other settings in a bndrun file and create a fat jar that contains the OSGi framework as well as your bundle(s). The nice thing is that bnd(tools) provides nice tooling to do this professionally.

So while getting up and running with the first solution is faster, it will always involve manual work. The bndtools approach can fully automate the packaging in a maven build .. which is probably what you want to have in the long run.

I have created a sample project that shows this for maven (I guess you use maven as you mention a target dir).

You need to create an executable JAR. This JAR then includes a launcher for OSGi, the Framework, and it know where to find the modules.

Bndtools has an Export task for this purpose. You have to create a bndrun file, add initial requirements, resolve it, and then export it. You can also automate it with Gradle.

You can follow the OSGi enRoute Quick Start tutorial to see how to build an OSGi application as an executable JAR.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM