OSGI容器中的Scala? [英] Scala in OSGI container?

查看:109
本文介绍了OSGI容器中的Scala?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Scala中编码我的捆绑软件,然后将其部署到OSGI容器中?

How can I code my bundle in Scala and then deploy it into OSGI container?

我是先将其编译为"java",还是可以将scala直接部署到OSGI中并使用某种捆绑软件来识别它?

Do I compile it into "java" first or can i deploy scala straight into OSGI and use some kind of bundles to recognize it?

任何指针都很棒. 目前,我正在使用Apache Felix作为我的osgi-container,但是只要对通用概念进行简单的说明就足以使我入门.

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.

推荐答案

感谢大家的回答,您使我找到了解决方案!在这里,我将以更简单的术语来描述它,以吸引更多的受众.

目标:scala中的代码,部署到OSGi.

Goal: Code in scala, deploy to OSGi.

使用的工具:

  1. Equinox OSGi实施
  2. Eclipse Helios 3.6,
  3. Scala 2.9

过程

  1. 为Eclipse安装 Scala IDE .查找适用于Scala 2.9和Eclipse 3.6的版本
  2. 在Eclipse中创建新的 Scala Project .
  3. 通过右键单击项目并选择:Configure -> Convert to Plug-in Projects...

  1. Install Scala IDE for Eclipse. Find version that will work with Scala 2.9 and Eclipse 3.6
  2. Create new Scala Project in Eclipse.
  3. Convert the project to OSGi bundle by right clicking on it and selecting: Configure -> Convert to Plug-in Projects...

现在,下一部分是我被卡住的地方.您会看到,现在我们需要将此捆绑包(我们的项目)部署到OSGi环境.但是,我们缺少必须在OSGi容器中才能提供我们在包中使用的所有Scala包API的Scala类(或包含这些类的捆绑包).不幸的是,找到"Scala捆绑包"并不是那么容易.在环顾四周之后,事实证明,由于某种原因,Scala捆绑包实际上位于Sonatype Maven存储库.

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.

调整清单文件以需要Scala捆绑包(我很确定这是捆绑包依赖项(即Require-Bundle)实际上非常安全的地方-毕竟,您永远不会运行没有Scala的Scala代码!):

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!):

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Scala Hello
Bundle-SymbolicName: com.test.scala.hello
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: drozzy
Import-Package: org.osgi.framework;version="1.5.0"
Bundle-Activator: com.test.scala.hello.Activator
Require-Bundle: scala-library;bundle-version="2.9.1"

  • 现在,您可以在Scala中编写捆绑激活器了(呼!):

  • Now, you can write your bundle activator in Scala (wooho!):

    //Activator.scala
    package com.test.scala.hello
    import java.lang.System
    import org.osgi.framework.BundleActivator
    import org.osgi.framework.BundleContext
    
    class Activator extends BundleActivator {
      def start(context: BundleContext) {
          System.out.println("Hello world from scala!");
      }
      def stop(context: BundleContext){}
    }
    

  • 将您的项目作为捆绑部署到OSGi容器中,并注意"scala的世界!"消息.

  • Deploy your project as a bundle to OSGi container and look out for the "Hello world from scala!" message.

    这篇关于OSGI容器中的Scala?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆