问题描述
我正在尝试按照本教程进行操作:
I am trying to follow this tutorial:
但是我不明白目录结构.我在哪里放置 Activator.java 文件?相对于 Activator.java 文件,我应该将 MANIFEST.MF 放在哪里?
But I don't understand the directory structure. Where do I place the Activator.java file? Where, relative to the Activator.java file do I place the MANIFEST.MF?
在本教程中,当我尝试编译 Activator.java 文件时,出现 org.osgi.framework 不存在的错误.我在哪里可以得到 org.osgi.framework 包,它应该安装在哪里?javac build命令如何知道如何找到org.osgi.framework包?
In this tutorial when I try to compile the Activator.java file, I get errors that org.osgi.framework does not exist. Where can I get the org.osgi.framework package and where should it be installed? How does the javac build command know how to find the org.osgi.framework package?
我正在寻找一个教程来解释什么是 Karaf/Felix 框架以及如何让简单的示例工作.
I am looking for a tutorial that explains what Karaf/Felix framework is and how to get simple examples to work.
我也尝试遵循本教程:http://kevinboone.net/osgitest.html
但它已经过时,并且 Tick 捆绑步骤的构建失败.具体来说,命令:
but it is out of date and the building of the Tick bundle step fails. Specifically, the command:
javac -d target/tick/classes -classpath /path/to/karaf/lib/karaf.jar src/net/kevinboone/osgitest/tick/*.java
没有意义,因为我从 karaf 下载站点.
Does not make sense because there is not a file "karaf.jar" in my karaf installation that I downloaded from karaf download site.
在清单文件中,有一行:
In the manifest file, there is the line:
Import-Package: org.osgi.framework
但是这个包在 karaf 安装中似乎不存在?
but this package does not seem to exist in the karaf installation?
推荐答案
felix 教程已经过时了.
The felix tutorial is horribly outdated.
如果你想学习 OSGi,我可以推荐 Apache Karaf 演示 和 教程 以及 enroute 示例.
If you want to learn OSGi I can recommend the Apache Karaf demo and tutorials as well as the enroute examples.
还是要回答问题.您可以在 osgi 核心规范 jar 和 felix jar 中找到包 org.osgi.framework
.因此,在编译期间,这些 jar 文件之一需要位于类路径中.
Still to answer the question. You find the package org.osgi.framework
in the osgi core spec jar and also in the felix jar. So one of these jars needs to be on the classpath during your compile.
您不应手动创建清单.而是使用像 maven-bundle-plugin 这样的插件来创建它.然后,您可以将 Activator 放置在您想要的任何位置,只需给该工具一个提示即可.
You should not create the manifest by hand. Instead use a plugin like the maven-bundle-plugin to create it. You can then place the Activator where ever you want and simply need to give the tool a hint where it is.
不要在 Activator 和其他低级 OSGi API 上投入太多时间.它们不是您应该编写代码的方式.而是看看声明式服务.它允许使用注释连接您的类并处理困难的低级任务.
Do not invest too much time into Activator and other low level OSGi APIs. They are not the way you should write code. Instead take a look at declarative services. It allows to wire your classes using annotations an takes care of the difficult low level tasks.
本教程的问题在于他们使用了非常低级的命令,例如 javac
.现在你应该总是使用诸如 Maven 或 Gradle 之类的构建工具并在那里声明依赖项.我链接的教程和示例都提供了很好的构建,您也可以将其用于以后的生产代码.
The issue with the tutorial is that they use really low level commands like javac
. Nowadays you should always use a build tool such as Maven or Gradle and declare the dependencies there. The tutorials and examples I linked all provide nice builds that you can also use for your later production code.
这篇关于在哪里可以找到和安装 org.osgi.framework 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!