如何使用OpenJDK 7编译mavenized OSGi 4.3包?

我正在尝试使用OpenJDK7针对OSGi规范4.3编译我的OSGi包但我收到错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5:compile (default-compile) on project example: Compilation failure [ERROR] /tmp/baka/example/src/main/java/org/example/Activator.java:[14,24] error: type ServiceReference does not take parameters 

这是我的Activator.java:

 package org.example; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceReference; public class Activator implements BundleActivator { @Override public void start(BundleContext bundleContext) throws Exception { ServiceReference ref = bundleContext.getServiceReference(Runnable.class); } @Override public void stop(BundleContext bundleContext) throws Exception { } } 

和我的pom.xml:

  4.0.0 org.example example 1.0-SNAPSHOT bundle example http://maven.apache.org  UTF-8    org.osgi org.osgi.core 4.3.0      org.apache.felix maven-bundle-plugin 2.3.7 true   org.example org.example.Activator       

当我使用OpenJDK 6时,不会出现此错误。任何提示如何使用OpenJDK 7?

您需要使用Java 7中的javac重新编译OSGi源代码.OSGi使用-target jsr14使用Java 6 javac编译代码。 Java 7 javac删除了对这些类文件进行编译的支持: http : //bugs.sun.com/bugdatabase/view_bug.do?video_id = 7078419

从R5开始,OSGi将不再发布-target jsr14类文件。

[2012年10月31日更新]

OSGi现在为Java 7提供了重新编译的4.3 jar文件。请参阅http://blog.osgi.org/2012/10/43-companion-code-for-java-7.html