2011-08-18 66 views
0

如何構建使用Scala(2.9.1.RC3)和PDE(Eclipse Helios)的OSGi包。我正在使用Scala IDE(2.0.0-beta)構建項目並將其轉換爲PDE項目。 我的MANIFEST.MF是這樣的:使用Eclipse PDE和Scala IDE構建OSGi模塊和Scala

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 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?

在此先感謝

+0

您的激活器類是否實現了java接口BundleActivator?所有類型都是由包中的激活器類引用的,還是導入了包中的? –

+0

@ bj-hargrave是的。我也會發布代碼。 – adelarsq

+1

您的包似乎並未導入Scala標準庫包。不幸的是,我不知道這會是什麼,但可能至少需要'scala'包。看起來你正在使用scala集合,所以你需要導入'scala.collection',並且你可能還需要'scala.runtime'。 –

回答

0

我發現這個愚蠢的問題。何時導出字段「使用在工作區中編譯的類文件」未標記。 Works,但還有另一個問題,即.scala文件在導出的.jar文件中。