我有一个 OSGi 项目,并且正在使用 Maven。在 bundle 中,我需要导入 org.osgi.util.tracker.ServiceTracker,并创建一个属性:
...
import org.osgi.util.tracker.ServiceTracker;
...
private ServiceTracker<Object, Object> serviceTracker;
我的依赖项中显然有 org.eclipse.osgi,如下所示(我的 pom.xml 的一部分)。
<dependencies>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.osgi</artifactId>
<version>3.8.0.v20120529-1548</version>
<scope>provided</scope>
</dependency>
</dependencies>
在 Eclipse 中,我可以找到该类的定义。
public class ServiceTracker<S, T> implements
ServiceTrackerCustomizer<S, T>
{
...
}
但是,当我通过maven命令编译我的项目时:
mvn clean install
我收到错误:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project <my project name>: Compilation failure: Compilation failure:
[ERROR] <link to my source code dir>/Activator.java:[75,27] type
org.osgi.util.tracker.ServiceTracker does not take parameters
到底发生了什么?
最佳答案
我怀疑您正在使用 Java 7 编译代码。OSGi 发布了使用未记录的 -target jsr14
标志编译的类文件。 Javac 7 拒绝识别这些类文件中的通用签名。请参阅http://blog.osgi.org/2012/10/43-companion-code-for-java-7.html .
此外,您不应该针对 Equinox 实现进行编译,而应该针对 OSGi 配套代码 jar 进行编译。您需要 4.3.1 或更高版本。请参阅http://search.maven.org/#artifactdetails|org.osgi|osgi.core|4.3.1|jar .
关于java - 错误: type org. osgi.util.tracker.ServiceTracker不接受参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26481653/