OSGI 容器中的 Scala?
如何在 Scala 中编码我的包,然后将其部署到 OSGI 容器中?
我是先将它编译成“java”,还是可以将 scala 直接部署到 OSGI 中并使用某种包来识别它?
任何指点都会很棒。 目前,我使用 Apache Felix 作为我的 osgi 容器,但只需对通用概念进行简单的解释就足以让我开始。
How can I code my bundle in Scala and then deploy it into OSGI container?
Do I compile it into "java" first or can i deploy scala straight into OSGI and use some kind of bundles to recognize it?
Any pointers would be great.
Currently I am using Apache Felix as my osgi-container, but just a simple explanation of generic concepts would suffice to get me started.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
感谢大家的回答,你们引导我找到了解决方案!我将在这里用更简单的术语为更广泛的受众描述它。
目标:用 scala 编写代码,部署到 OSGi。
使用工具:
流程
Scala 项目
。右键单击项目并选择:
配置 -> 将项目转换为 OSGi 包转换为插件项目...
现在,下一部分是我陷入困境的地方。您看,现在我们需要将此捆绑包(我们的项目)部署到 OSGi 环境。然而,我们缺少必须位于 OSGi 容器中的 Scala 类(或包含这些类的包)才能提供我们在包中使用的所有 Scala 包 API。不幸的是,找到“Scala 包”并不那么容易。在环顾四周之后,事实证明,出于某种原因,Scala 包实际上位于 Sonatype Maven 存储库。
下载
scala-library-2.9.1.jar
从 Sonatype Maven 存储库,并将其部署(通过最适合您的方式)到您的 OSGi 容器。调整你的清单文件以要求 Scala 包(我很确定这是一个包依赖项(即 Require-Bundle)实际上非常安全的地方 - 毕竟,如果没有它,你将永远不会运行你的 Scala 代码) Scala!):
现在,您可以在 Scala 中编写捆绑激活器(哇哦!):
将您的项目作为捆绑包部署到 OSGi 容器,并留意“Hello world from scala!”
Thanks to everyone for the answers, you led me to the solution! I will describe it here in a little simpler terms for a wider audience.
Goal: Code in scala, deploy to OSGi.
Tools used:
Procedure
Scala Project
in Eclipse.Convert the project to OSGi bundle by right clicking on it and selecting:
Configure -> Convert to Plug-in Projects...
Now, the next part was where I got stuck. You see, now we need to deploy this bundle (our project) to OSGi environment. However we are missing the Scala classes (or bundle that contains those classes) that have to be in OSGi container to provide all the Scala packages API we use in our bundle. Unfortunately finding the "Scala bundle" is not that easy. After looking around it turns out, that for some reason, Scala bundle is actually located in the Sonatype Maven Repository.
Download the
scala-library-2.9.1.jar
from the appropriate location in the Sonatype Maven Repository, and deploy it (by means most comfortable for you) to your OSGi container.Adjust your manifest file to require the Scala bundle (I am pretty sure that this is one place where bundle dependency (i.e. Require-Bundle) is actually pretty safe - after all, you will never run your Scala code without Scala!):
Now, you can write your bundle activator in Scala (wooho!):
Deploy your project as a bundle to OSGi container and look out for the "Hello world from scala!" message.
ScalaModules
作者的快速介绍视频 2010 年 Scala 日
ScalaModules
A quick intro video by the author here Scala days 2010
OSGi 不关心你用什么语言编写代码:JVM 字节码只是 JVM 字节码。因此:
您会注意到您的包依赖于 Scala 库。同样,这也没什么奇怪的,就像 Java 代码中存在依赖关系一样。为了解决这些依赖关系,您需要从 scala-lang-osgi 安装 Scala 库包
OSGi does not care what language you write your code in: JVM bytecode is just JVM bytecode. So:
You'll notice that your bundle has dependencies on the Scala library. Again there is nothing strange about this, it's just like having dependencies in you Java code. In order for those dependencies to resolve, you need to install the Scala library bundle from scala-lang-osgi
它没有什么特别之处:用 Scala 编写代码,并通过提供必要的包元数据和服务描述符将其包装为 OSGi 包,就像使用 Java 一样。
Apache Maven 可以在此过程中为您提供帮助。查看 Guggla 项目(Scala 脚本引擎)的工作示例。 maven-bundle-plugin 在 < a href="https://github.com/guggla/guggla/blob/master/pom.xml" rel="noreferrer">pom.xml 负责生成捆绑包元数据并将其包含在最终版本中jar 文件。它指的是服务描述符 您需要提供的 xml 文件。
There is nothing special to it: write your code in Scala and wrap it up as an OSGi bundle by providing the necessary bundle meta data and service descriptors as you would do with Java.
Apache Maven can help you in the process. Have a look at the Guggla Project (a Scala script engine) for a working example. The maven-bundle-plugin in the pom.xml takes care of generating and including the bundle meta data in the final jar file. It refers to the service descriptor xml file which you need to provide.