【问题标题】:How to embed a library JAR in an OSGi bundle using Tycho如何使用 Tycho 将库 JAR 嵌入到 OSGi 包中
【发布时间】:2015-04-17 00:47:22
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: maven jar osgi dependency-management tycho


    【解决方案1】:

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

    1. 在pom.xml中,配置maven-dependency-plugincopy目标

      <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>
      
    2. 编辑 MANIFEST.MF 以将库添加到 OSGi 包类路径

      Bundle-ClassPath: ., lib/restfb.jar
      
    3. 编辑 build.properties 以将库包含在 Tycho 打包的 JAR 中

      bin.includes = META-INF/,\
                     .,\
                     lib/restfb.jar
      

    【讨论】:

      【解决方案2】:

      我认为您想要的是在 POM 中具有编译时范围的依赖项,如下例所示:使用正确的工件和版本信息来获取您想要的项目。您应该调查 poms 的 maven ref 的依赖项部分

      <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.4</version>
      <scope>compile</scope>
      </dependency>
      

      【讨论】:

        猜你喜欢
        • 2010-11-25
        • 2018-10-05
        • 2019-11-03
        • 2012-05-07
        • 2015-05-13
        • 2016-08-20
        • 1970-01-01
        • 1970-01-01
        • 2012-08-05
        相关资源
        最近更新 更多