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>
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>