使用 Eclipse PDE 和 Scala IDE 通过 Scala 构建 OSGi 模块

发布于 2024-11-30 04:34:01 字数 4260 浏览 1 评论 0原文

如何构建使用 Scala (2.9.1.RC3) 和 PDE (Eclipse Helios) 的 OSGi 捆绑包。我正在使用 Scala IDE(2.0.0-beta)构建项目并将其转换为 PDE 项目。 我的 MANIFEST.MF 是这样的:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ScalaTest1
Bundle-SymbolicName: ScalaTest1
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: scalatest1.Activator
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6

项目构建没有错误,但是启动捆绑包时出现此异常(使用 Apache Felix 3.2.2):

org.osgi.framework.BundleException: Not found: scalatest1.Activator
        at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:3812)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1899)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1822)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:927)
        at org.apache.felix.gogo.command.Basic.start(Basic.java:758)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.felix.gogo.runtime.Reflective.method(Reflective.java:136)
        at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:469)
        at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:395)
        at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
        at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)
        at org.apache.felix.gogo.shell.Console.run(Console.java:62)
        at org.apache.felix.gogo.shell.Shell.console(Shell.java:203)
        at org.apache.felix.gogo.shell.Shell.gosh(Shell.java:128)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.felix.gogo.runtime.Reflective.method(Reflective.java:136)
        at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:469)
        at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:395)
        at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
        at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)
        at org.apache.felix.gogo.shell.Activator.run(Activator.java:75)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: scalatest1.Activator not found by ScalaTest1 [27]
        at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:812)
        at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:72)
        at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1807)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.felix.framework.ModuleImpl.getClassByDelegation(ModuleImpl.java:670)
        at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:3808)
        ... 33 more

代码:

package scalatest1

import org.osgi.framework._

class Activator extends BundleActivator {
  def start(context: BundleContext) {
    println("Hello, World!");

    val bundleNames = context.getBundles()
      .map(b => b.getSymbolicName())
      .filter(b => b != context.getBundle());
    println("Installed bundles: " + bundleNames.mkString(", "));
  }

  def stop(context: BundleContext) {
    println("Goodbye, World!");
  }
}

该过程出了什么问题?如何正确映射类Activator?

提前致谢

How to build an OSGi bundle that use Scala (2.9.1.RC3) with PDE (Eclipse Helios). I'm using Scala IDE (2.0.0-beta) to build the project and converting this to PDE project.
My MANIFEST.MF is like that:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ScalaTest1
Bundle-SymbolicName: ScalaTest1
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: scalatest1.Activator
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6

The project build without errors, but when start the bundle this exception appears (using Apache Felix 3.2.2):

org.osgi.framework.BundleException: Not found: scalatest1.Activator
        at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:3812)
        at org.apache.felix.framework.Felix.activateBundle(Felix.java:1899)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1822)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:927)
        at org.apache.felix.gogo.command.Basic.start(Basic.java:758)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.felix.gogo.runtime.Reflective.method(Reflective.java:136)
        at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:469)
        at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:395)
        at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
        at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)
        at org.apache.felix.gogo.shell.Console.run(Console.java:62)
        at org.apache.felix.gogo.shell.Shell.console(Shell.java:203)
        at org.apache.felix.gogo.shell.Shell.gosh(Shell.java:128)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.apache.felix.gogo.runtime.Reflective.method(Reflective.java:136)
        at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:82)
        at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:469)
        at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:395)
        at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
        at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
        at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:89)
        at org.apache.felix.gogo.shell.Activator.run(Activator.java:75)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: scalatest1.Activator not found by ScalaTest1 [27]
        at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:812)
        at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:72)
        at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1807)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.apache.felix.framework.ModuleImpl.getClassByDelegation(ModuleImpl.java:670)
        at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:3808)
        ... 33 more

And the code:

package scalatest1

import org.osgi.framework._

class Activator extends BundleActivator {
  def start(context: BundleContext) {
    println("Hello, World!");

    val bundleNames = context.getBundles()
      .map(b => b.getSymbolicName())
      .filter(b => b != context.getBundle());
    println("Installed bundles: " + bundleNames.mkString(", "));
  }

  def stop(context: BundleContext) {
    println("Goodbye, World!");
  }
}

What is wrong with the process? How to map correctly the class Activator?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不知在何时 2024-12-07 04:34:01

请参阅 http://www.michel-kraemer.com/ scala-projects-with-eclipse-pde-build-2 是一种无需导出 JAR 中的 .scala 文件即可完成此操作的方法。

See http://www.michel-kraemer.com/scala-projects-with-eclipse-pde-build-2 for a way to do this without exporting .scala files in JAR.

挽梦忆笙歌 2024-12-07 04:34:01

我发现了一个愚蠢的问题。导出时,“使用工作区中编译的类文件”字段未标记。有效,但还有另一个问题,.scala 文件位于导出的 .jar 文件中。

I found the silly problem. When was exporting the field "Use class files compiled in the workspace" was unmarked. Works, but there is another problem, that the .scala files are in the .jar file exported.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文