简体   繁体   English

如何从命令行运行osgi模块?

[英]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: 我正在尝试使用以下命令从命令行运行OSGI模块:

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? 当我提取jar文件时,MANIFEST.MF是否存在?

Which manifest did I forget? 我忘记了哪个清单?

You can not simply run a bundle by itself. 您不能简单地单独运行捆绑软件。 A bundle needs to run inside an OSGi framework. 捆绑软件需要在OSGi框架内运行。 So you could for example download Apache felix and put your bundle into the felix directory that picks up bundles to load. 因此,例如,您可以下载Apache felix,然后将捆绑软件放入felix目录中,该目录可以选择要加载的捆绑软件。 In this case you would start felix and felix would then load your bundle. 在这种情况下,您将启动felix,然后felix将加载您的捆绑软件。

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). Peter的建议是在bndrun文件中定义一组捆绑软件和其他设置,并创建一个包含OSGi框架以及捆绑软件的胖子。 The nice thing is that bnd(tools) provides nice tooling to do this professionally. 不错的是,bnd(tools)提供了很好的工具来专业地做到这一点。

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. bndtools方法可以完全自动化maven构建中的打包。从长远来看,这可能是您想要的。

I have created a sample project that shows this for maven (I guess you use maven as you mention a target dir). 我创建了一个示例项目 ,为maven显示了这一点(我猜您在提到目标目录时使用了maven)。

You need to create an executable JAR. 您需要创建一个可执行的JAR。 This JAR then includes a launcher for OSGi, the Framework, and it know where to find the modules. 然后,此JAR包括OSGi的启动器,框架,并且知道在哪里可以找到模块。

Bndtools has an Export task for this purpose. Bndtools为此有一个导出任务。 You have to create a bndrun file, add initial requirements, resolve it, and then export it. 您必须创建一个bndrun文件,添加初始需求,解决该问题,然后将其导出。 You can also automate it with Gradle. 您也可以使用Gradle使它自动化。

You can follow the OSGi enRoute Quick Start tutorial to see how to build an OSGi application as an executable JAR. 您可以按照OSGi enRoute快速入门教程了解如何将OSGi应用程序构建为可执行JAR。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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