简体   繁体   English

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

[英]How to compile mavenized OSGi 4.3 bundle with OpenJDK 7?

i am trying to compile my OSGi bundle against OSGi specification 4.3 using OpenJDK7 but i am getting error: 我正在尝试使用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

here is my Activator.java: 这是我的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<Runnable> ref = bundleContext.getServiceReference(Runnable.class);
    }

    @Override
    public void stop(BundleContext bundleContext) throws Exception {
    }
}

and my pom.xml: 和我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>bundle</packaging>

    <name>example</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>org.osgi.core</artifactId>
            <version>4.3.0</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Private-Package>org.example</Private-Package>
                        <Bundle-Activator>org.example.Activator</Bundle-Activator>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

This error is not appears when i am using OpenJDK 6. Any hints how to get it working with OpenJDK 7? 当我使用OpenJDK 6时,不会出现此错误。任何提示如何使用OpenJDK 7?

You need to recompile the OSGi source code with javac from Java 7. OSGi compiled the code with Java 6 javac using -target jsr14. 您需要使用Java 7中的javac重新编译OSGi源代码.OSGi使用-target jsr14使用Java 6 javac编译代码。 Java 7 javac removed support for compiling against such class files: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7078419 Java 7 javac删除了对这些类文件进行编译的支持: http//bugs.sun.com/bugdatabase/view_bug.do?video_id = 7078419

Starting with R5, OSGi will no longer ship -target jsr14 class files. 从R5开始,OSGi将不再发布-target jsr14类文件。

[Updated 31 Oct 2012] [2012年10月31日更新]

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM