Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

[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:

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:

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

like image 509
Alexander Tumin Avatar asked Jun 06 '12 09:06

Alexander Tumin


People also ask

What is OSGi Java container?

OSGi facilitates creating and managing modular Java components (called bundles) that can be deployed in a container. As a developer, you use the OSGi specification and tools to create one or more bundles. OSGi defines the lifecycle for these bundles. It also hosts them and supports their interactions in a container.

What is activator OSGi?

In OSGi, all service implementations are packaged into bundles. You can make a bundle lifecycle-aware by including a bundle activator to manage the lifecycle of the bundle. A bundle activator is a Java class that implements the org. osgi. framework.

How does OSGi framework work?

How does OSGi work? OSGi is a set of specifications that define a dynamic component system for Java. These specifications allow for a development model in which an application is composed of several components, and then packed into bundles. These components communicate locally and through the network via services.


1 Answers

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 removed support for compiling against such class files: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7078419

Starting with R5, OSGi will no longer ship -target jsr14 class files.

[Updated 31 Oct 2012]

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

like image 94
BJ Hargrave Avatar answered Oct 04 '22 16:10

BJ Hargrave