将现有的java项目转换为osgi包的最佳方式
我们有很多组件,我们想要模块化只有几个开始.想知道在所有这些组件中创建捆绑包的最佳方法(在我的构建环境的上下文中)是什么?
我的环境:Java 6,Maven 2.2.1,Hudson 技术:Spring 3.0.5,WebSphere 7,Hibernate 3.2.x和大多数apache commons. 要求 >仅组合少量组件.其他的组件可以导出所有的包. 解决方法
首先,只需更改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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |