maven 创建osgi工程

Pax-Construct 是用来创建osgi工程的maven的插件,以后创建osgi架构的工程再也不用import一大堆plugin工程了。
http://www.ops4j.org/projects/pax/construct/ 是Pax插件官网的入门教程,简单的说分为以下几步:
1)http://repo1.maven.org/maven2/org/ops4j/pax/construct/scripts/1.4/scripts-1.4.zip 是pax插件的下载地址,下载了该插件后设置环境变量就可以使用了。
2)pax-create-project -g examples -a test 该命令是创建一个OSGI的工程, -g 代表groupId为 examples ; -a 代表artifactId 为test
3)进入到test 目录创建一个bundle。命令如下:cd test
pax-create-bundle -p org.example.pkg -n test.bundle 其中-p 代表包名 -n代表bundle的名称
4)mvn pax:eclipse -DdownloadSources 编译代码,导入到eclipse中
5)mvn clean install pax:provision 部署工程到felix 。在这一步有可能报如下的错误:
[color=red]An API incompatibility was encountered while executing org.ops4j:maven-pax-plugin:1.4:compile: java.lang.NoSuchMethodError: org.apache.maven.project.MavenProject.addPlugin(Lorg/apache/maven/model/Plugin;)V[/color] 该错误的原因是Pax-Construct 试图改变maven的编译接口以更好的适应osgi。解决办法为修改poms/pom.xml文件。
原文件:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.ops4j</groupId>
<artifactId>maven-pax-plugin</artifactId>
<!--
| enable improved OSGi compilation support for the bundle life-cycle.
| to switch back to the standard bundle life-cycle, move this setting
| down to the maven-bundle-plugin section
-->
[color=red]<extensions>true</extensions>[/color] <!-- 修改这里-->
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.3</version>
</plugin>
</plugins>
</pluginManagement>
修改后文件:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.ops4j</groupId>
<artifactId>maven-pax-plugin</artifactId>
<!--
| enable improved OSGi compilation support for the bundle life-cycle.
| to switch back to the standard bundle life-cycle, move this setting
| down to the maven-bundle-plugin section
-->
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>1.4.3</version>
[color=red]<extensions>true</extensions>[/color] <!-- 移动到这里 -->
</plugin>
</plugins>
</pluginManagement>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值