`
zcmor
  • 浏览: 21354 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

maven 创建osgi工程

    博客分类:
  • 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 。在这一步有可能报如下的错误:
     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  该错误的原因是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
          -->
          <extensions>true</extensions>                        <!-- 修改这里-->
        </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>
          <extensions>true</extensions>                        <!-- 移动到这里 -->
        </plugin>
      </plugins>
    </pluginManagement>
   
分享到:
评论
3 楼 paladin1988 2013-01-21  
多谢了,兄弟。。
2 楼 谁主沉浮 2012-08-02  
royboy 写道
很不错的文章

1 楼 royboy 2012-05-12  
很不错的文章

相关推荐

Global site tag (gtag.js) - Google Analytics