微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将现有的java项目转换为osgi包的最佳方式

我们有很多组件,我们想要模块化只有几个开始.想知道在所有这些组件中创建捆绑包的最佳方法(在我的构建环境的上下文中)是什么?

我的环境:Java 6,Maven 2.2.1,Hudson

技术:Spring 3.0.5,WebSphere 7,Hibernate 3.2.x和大多数apache commons.

要求

>仅组合少量组件.其他的组件可以导出所有的包.
>当导入到eclipse时,我应该能够看到导入包的捆绑作为构建路径中的依赖关系(mvn eclipse:eclipse似乎不这样做)

解决方法

首先,只需更改MANIFEST.MF条目,使您的所有工件成为捆绑 – 它们显然不会神奇地工作,但它是一个很好的非破坏性的第一步.

当使用maven-bundle-plugin时,您可以设置扩展名和supportedProjectTypes,因为您可能会遇到CI构建问题,如果包装类型为bundle,则Maven repos和m2e将失败(请参阅end).

在早期测试您最有风险/核心的外部依赖关系 – 例如,如果您使用JPA进行持久化,那么请确保提供程序在具有域绑定和JDBC驱动程序的Osgi环境中工作.

如果您从Java EE / Spring迁移,请查看Karaf或Virgo.但是,如果您的组件用于嵌入式系统或没有外部依赖关系,那么Felix或Equinox可能就足够了(如果是这样,请检查pax-url项目).

可能值得编辑您的问题,以更具体的域/技术?

eclipse:eclipse仅在项目首次配置时生成,m2e的生命周期问题可能会有点痛苦,但远远优于使用旧的eclipse插件.

以下将添加清单条目到您现有的工件,而不用任何其他方式更改它们.它告诉标准的maven jar和war插件来使用由maven-bundle-plugin生成的MANIFEST.MF.

把它放在父POM中:

<pluginManagement>
<plugin>
    <groupId>org.apache.Felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.3.7</version>
    <extensions>true</extensions>
    <configuration>
        <archive>
            <addMavendescriptor>true</addMavendescriptor>
        </archive>
        <supportedProjectTypes>
            <supportedProjectType>jar</supportedProjectType>
            <supportedProjectType>war</supportedProjectType>
        </supportedProjectTypes>
        <instructions>
            <Built-By>${project.organization.name}</Built-By>
            <Bundle-vendor>${project.organization.name}</Bundle-vendor>
            <Bundle-ContactAddress>${project.organization.url}</Bundle-ContactAddress>
            <Bundle-Description>${project.description}</Bundle-Description>
            <Bundle-DocURL>${bundle.doc.url}</Bundle-DocURL>
            <Bundle-Category>${bundle.category}</Bundle-Category>
            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
            <Bundle-Version>${project.version}</Bundle-Version>

            <Import-Package>*</Import-Package>
            <Export-Package>*</Export-Package>
        </instructions>
    </configuration>
    <executions>
        <execution>
            <id>bundle</id>
            <goals>
                <goal>manifest</goal>
            </goals>
            <phase>prepare-package</phase>
            <inherited>true</inherited>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.3.1</version>
    <configuration>
        <archive>
            <manifestFile>${project.build.outputDirectory}/meta-inf/MANIFEST.MF</manifestFile>
        </archive>
    </configuration>
</plugin>

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <executions>
        <execution>
            <id>create-war</id>
            <phase>package</phase>
            <goals>
                <goal>war</goal>
            </goals>
            <inherited>true</inherited>
        </execution>
    </executions>
    <configuration>
        <archive>
            <manifestFile>${project.build.outputDirectory}/meta-inf/MANIFEST.MF</manifestFile>
        </archive>
    </configuration>
</plugin>
</pluginManagement>

然后在孩子POM中,你可以简单地做:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.Felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
        </plugin>
        <!-- Below is mutually exclusive: Either jar or war plugin -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
        </plugin>
    </plugins>
</build>

原文地址:https://www.jb51.cc/java/123205.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐