首先仅更改 MANIFEST.MF 条目,以便所有工件都成为捆绑包 - 它们显然不会神奇地工作,但这是一个很好的非破坏性第一步。
使用 maven-bundle-plugin 时确保设置extensions
and supportedProjectTypes
因为如果打包类型为 CI 构建,Maven 存储库和 m2e 可能会失败bundle
(见末尾)。
尽早测试您最危险/核心的外部依赖项 - 例如,如果您使用 JPA 进行持久性,那么请确保提供程序在具有您的域捆绑包和 JDBC 驱动程序的 OSGi 环境中工作。
如果您要从 Java EE/spring 迁移,请考虑 Karaf 或 Virgo。但是,如果您的组件用于嵌入式系统或没有外部依赖项,Felix 或 Equinox 可能就足够了(尽管请查看pax-url http://team.ops4j.org/wiki/display/paxurl/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>