質問

I am developing an Eclipse plugin and would like to leverage the Jersey OSGI bundle hosted on SpringSource but once the bundle is pulled down it is not consumed. My question is how do I declare, in my POM or MANIFEST, that I want the Jersey bundle to be consumed as a dependency?

My project consists of a simple update site, a feature that contains the plugin, and the plugin itself, all created following the book: "Eclipse 4 Plug-in Development by Example Beginner's Guide". I am using Tycho as my build tool with a parent POM holding the target platform information and the other projects as modules.

My parent POM is below:

<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>com.inin.testing.eclipse</groupId>
    <artifactId>com.inin.testing.eclipse.parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <tycho-version>0.18.1</tycho-version>
        <eclipse>http://download.eclipse.org/releases/kepler</eclipse>
    </properties>

    <modules>
        <module>com.inin.testing.eclipse.update</module>
        <module>com.inin.testing.eclipse.feature.testcase</module>
        <module>com.inin.testing.eclipse.plugin.tcdb</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-maven-plugin</artifactId>
                <version>${tycho-version}</version>
                <extensions>true</extensions>
            </plugin>

            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>target-platform-configuration</artifactId>
                <version>${tycho-version}</version>
                <configuration>
                    <resolver>p2</resolver>
                    <pomDependencies>consider</pomDependencies>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>kepler</id>
            <layout>p2</layout>
            <url>${eclipse}</url>
        </repository>
        <repository>
            <id>com.springsource.repository.bundles.release</id>
            <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
            <url>http://repository.springsource.com/maven/bundles/release</url>
        </repository>
        <repository>
            <id>com.springsource.repository.bundles.external</id>
            <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
            <url>http://repository.springsource.com/maven/bundles/external</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.jdt</groupId>
            <artifactId>core</artifactId>
            <version>3.3.0-v_771</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>com.springsource.com.sun.jersey</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
</project>

The plugin POM is as below:

<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>com.inin.testing.eclipse</groupId>
    <artifactId>com.inin.testing.eclipse.update</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    <packaging>eclipse-repository</packaging>

    <parent>
        <groupId>com.inin.testing.eclipse</groupId>
        <artifactId>com.inin.testing.eclipse.parent</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
</project>

I also added the MANIFEST entry to the plugin project as given on SpringSource:

Import-Bundle: com.springsource.com.sun.jersey;version="[1.0.0,1.0.0]"

When I build with tycho there are no errors, but I am not able to use any of the classes that were supposed to be imported with the Jersey bundle.

I have tried moving the Jersey dependency from the parent to the child POM with the same result. Perhaps the solution is so obvious I cannot see it or I am on the completely wrong track. Any help would be great. Thanks!

役に立ちましたか?

解決

This all looks very good, except for one small mistake: The OSGi bundle manifest header needs to be Require-Bundle instead of Import-Bundle.

I'd recommend that you use the Eclipse PDE tooling to edit the bundle manifests. There are various caveats in the manifest file format that you can avoid by using the editor. In your particular case, you would have seen that the Import-Bundle header is not printed in bold, which means that it is not one of the known headers defined by OSGi or Eclipse.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top