首页 文章

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

提问于
浏览
3

我正在使用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 lib(例如作为依赖项)并嵌入到我的OSGi包jar中 . Maven / Tycho可以吗?怎么样?

2 回答

  • 11

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

    • 在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>
    
    • 编辑MANIFEST.MF以将库添加到OSGi包类路径中
    Bundle-ClassPath: ., lib/restfb.jar
    
    • 编辑build.properties以使该库包含在Tycho打包的JAR中
    bin.includes = META-INF/,\
                   .,\
                   lib/restfb.jar
    
  • 0

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

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

相关问题