【问题标题】:Eclipse plugin project not consuming OSGI bundle dependenciesEclipse 插件项目不使用 OSGI 包依赖项
【发布时间】:2013-10-04 14:28:54
【问题描述】:

我正在开发一个 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,结果相同。也许解决方案是如此明显,以至于我看不到它,或者我走错了路。任何帮助都会很棒。谢谢!

【问题讨论】:

    标签: eclipse-plugin tycho springsource


    【解决方案1】:

    这一切看起来都很好,除了一个小错误:OSGi bundle manifest header 需要是Require-Bundle 而不是Import-Bundle

    我建议您使用 Eclipse PDE 工具来编辑捆绑清单。使用编辑器可以避免清单文件格式中的各种警告。在您的特定情况下,您会看到 Import-Bundle 标头未以粗体打印,这意味着它不是 OSGi 或 Eclipse 定义的已知标头之一。

    【讨论】:

      猜你喜欢
      • 2015-03-12
      • 1970-01-01
      • 2020-09-14
      • 2013-11-16
      • 2012-01-20
      • 2011-02-21
      • 2015-02-18
      • 2015-10-04
      • 2012-11-28
      相关资源
      最近更新 更多