简体   繁体   English

如何使用Tycho使用Maven将Java项目构建为OSGi部署软件包?

[英]How to build java projects as OSGi Deployment Packages with Maven using Tycho?

I have some Java/OSGi projects that I wish to build and package as a single Deployment Package. 我有一些Java / OSGi项目,希望将其构建和打包为一个部署包。

I'm using Tycho to compile the sources for a particular target-platform, all dependencies are in a local p2 repository. 我正在使用Tycho来编译特定目标平台的源代码,所有依赖项都在本地p2存储库中。

If I set <packaging>eclipse-plugin</packaging> in my pom.xml the build goes fine but I get a .jar as output. 如果我在pom.xml中设置<packaging>eclipse-plugin</packaging> ,则构建可以正常进行,但输出为.jar。
When I use maven-bundle-plugin and set <packaging>bundle</packaging> the build breaks, because it compiles with the standard maven-compiler-plugin instead of Tycho. 当我使用maven-bundle-plugin并设置<packaging>bundle</packaging> ,构建会中断,因为它使用标准的maven-compiler-plugin而不是Tycho进行编译。

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.3.5</version>
    <extensions>true</extensions>
    <configuration>
        <manifestLocation>META-INF</manifestLocation>
        <instructions>
            <Bundle-SymbolicName>${project.artifactId};singleton:=true</Bundle-SymbolicName>
            <Bundle-Name>${project.name}</Bundle-Name>
            <Bundle-Version>${project.version}</Bundle-Version>
            <Import-Package>
                javax.net;resolution:=optional,
                javax.net.ssl;resolution:=optional
            </Import-Package>
            <Export-Package>my.project.package</Export-Package>
        </instructions>
    </configuration>
</plugin>

How do I force the compilation with Tycho? 如何使用Tycho强制编译? Or is there any other way to do what I need? 还是有其他方法可以满足我的需求?

That answer may come a bit late, but I recently created a Maven plugin "de.dentrassi.maven:osgi-dp" which can create those "DP"s. 这个答案可能有点晚了,但是我最近创建了一个Maven插件“ de.dentrassi.maven:osgi-dp”,它可以创建那些“ DP”。

See: https://ctron.github.io/osgi-dp/plugin-info.html 参见: https : //ctron.github.io/osgi-dp/plugin-info.html

You can either create a specialized "dp" packaging or re-use Eclipse Tycho's feature metadata: 您可以创建专门的“ dp”包装,也可以重复使用Eclipse Tycho的功能元数据:

<plugin>
    <groupId>de.dentrassi.maven</groupId>
    <artifactId>osgi-dp</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>build</goal>
            </goals>
        </execution>
    </executions>
</plugin>

For a full example of using Tycho for compiling and "osgi-dp" for creating the deployment package see the integration test at GitHub . 有关使用Tycho进行编译和使用“ osgi-dp”创建部署程序包的完整示例,请参见GitHub上集成测试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM