maven - 如何使用 Tycho 在 OSGi 包中嵌入库 JAR

标签 maven jar osgi dependency-management tycho

我使用 Maven 和 Tycho 插件来构建我的 OSGi 包。
在我的一个包中,我通过 restfb-1.7.0.jar 库使用了 facebook API。

目前,它直接放置在类路径上(在 Eclipse 中)并嵌入到具有以下 build.properties 配置的有效 OSGi 包 jar 文件中:

source.. = src/
output.. = bin/
bin.includes = META-INF/,\
           .,\
           lib/restfb-1.7.0.jar

现在我想从 Maven 下载这个 restfb 库(例如作为依赖项)并嵌入到我的 OSGi 包 jar 中。 Maven/Tycho 有可能吗?如何?

最佳答案

您需要以下配置才能使用 Tycho 将 JAR 嵌入到 OSGi 插件中:

  • 在 pom.xml 中,配置 copy maven-dependency-plugin的目标
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.10</version>
                <executions>
                    <execution>
                        <id>copy-libraries</id>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <item>
                                    <groupId>com.restfb</groupId>
                                    <artifactId>restfb</artifactId>
                                    <version>1.7.0</version>
                                </item>
                            </artifactItems>
                            <outputDirectory>lib</outputDirectory>
                            <stripVersion>true</stripVersion>
                            <overWriteReleases>true</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    
  • 编辑 MANIFEST.MF 将库添加到 OSGi 包类路径
    Bundle-ClassPath: ., lib/restfb.jar
    
  • 编辑 build.properties 以使库包含在 Tycho 打包的 JAR 中
    bin.includes = META-INF/,\
                   .,\
                   lib/restfb.jar
    
  • 关于maven - 如何使用 Tycho 在 OSGi 包中嵌入库 JAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28542595/

    相关文章:

    java - 如何为名称中包含 "requires"(连字符)的 Artifact 添加 "-"

    maven - 如何使用 Maven 将 rt.jar 嵌入到我的 WAR 中

    android - Jitpack doent 构建项目

    maven - 去掉 "-all"后缀的 JAR,当它是由 maven-publish gradle 插件发布时

    jar - 如何从 gradle jar 任务中提取公共(public)代码到方法中

    java - 使用 Log4j2 从静态方法记录

    java - 寻求有关使用 Blueprint 以编程方式访问 ServiceMix bundle 状态信息的指导

    java - Eclipse:如何导出插件中的文件夹

    jbehave/storyDurations.props 的 java.io.FileNotFoundException

    java - 通过 Java 发送电子邮件 - javax.mail.MessagingException : Could not connect to SMTP host: localhost, port: 587;