0

我正在开发一个 Eclipse 插件,并希望利用 SpringSource 上托管的 Jersey OSGI 捆绑包,但一旦捆绑包被拉下,它就不会被使用。我的问题是如何在我的 POM 或 MANIFEST 中声明我希望将 Jersey 捆绑包作为依赖项使用?

我的项目由一个简单的更新站点、一个包含插件的特性和插件本身组成,所有这些都是按照以下书创建的:“Eclipse 4 Plug-in Development by Example Beginner's Guide”。我使用 Tycho 作为我的构建工具,其父 POM 将目标平台信息和其他项目作为模块。

我的父 POM 如下:

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

插件POM如下:

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

我还将 MANIFEST 条目添加到 SpringSource 上给出的插件项目中:

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

当我使用 tycho 构建时,没有错误,但我无法使用任何应该与 Jersey 捆绑包一起导入的类。

我尝试将 Jersey 依赖项从父 POM 移动到子 POM,结果相同。也许解决方案是如此明显,以至于我看不到它,或者我走错了路。任何帮助都会很棒。谢谢!

4

1 回答 1

0

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.

于 2013-10-14T09:06:52.773 回答