`

在eclipse3.3上进行OSGI基础平台环境的搭建

阅读更多
1. dependecies repo的建立。
我们需要在eclipse上搭建一个OSGI的集成开发环境,实际上就是构建一个eclipse的目标平台(target),这个目标平台里面包括了一些我们要勇于OSGI开发的所必须用到的插件(Bundle),此外,剔除掉了一些我们不需要的插件来达到一个最干净,精简的OSGI开发环境的搭建,这样就有利于我们在eclipse上执行(run)或者调试(debug)一个方便的统一的OSGI开发环境来进行我们的OSGI相关开发工作。要完成这个目的,当然第一步工作是按照我们自己的需要去定制一个插件集,然后在利用eclipse的构建目标平台的功能(target definition)去关联到我们定义的这个插件集上,来完成一个自定义的OSGI开发平台的构建。
这里我们还是利用一个名叫Maven Dependency Plugin的maven插件来实施我们的插件集合的构建。关于这个插件的配置方法,相信官方网站上已经做了非常详尽的说明,这里由于我们只需要这个插件的Copying Project Dependencies功能,所以我们这里只简要的讲解一下这个功能的配置方法。
利用如下的一个模板配置你可以用来将配置在你的pom文件中的那些dependencies以及这些dependencies所依赖的dependencies拷贝到指定的目录:

xml 代码
 
  1. <project>  
  2.   [...]  
  3.   <build>  
  4.    <plugins>  
  5.      <plugin>  
  6.         <groupId>org.apache.maven.plugins</groupId>  
  7.         <artifactId>maven-dependency-plugin</artifactId>  
  8.         <executions>  
  9.           <execution>  
  10.             <id>copy-dependencies</id>  
  11.             <phase>package</phase>  
  12.             <goals>  
  13.               <goal>copy-dependencies</goal>  
  14.             </goals>  
  15.             <configuration>  
  16.               <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>  
  17.               <overWriteReleases>false</overWriteReleases>  
  18.               <overWriteSnapshots>false</overWriteSnapshots>  
  19.               <overWriteIfNewer>true</overWriteIfNewer>  
  20.             </configuration>  
  21.           </execution>  
  22.         </executions>  
  23.       </plugin>  
  24.     </plugins>  
  25.   </build>  
  26.   [...]  
  27. </project>  


当然你也可以通过设置excludeTransitive属性为true来显示的将pom中配置的dependencies所依赖的dependencies进行拷贝。
xml 代码
 
  1. [...]  
  2. <build>  
  3.  <plugins>  
  4.    <plugin>  
  5.       <groupId>org.apache.maven.plugins</groupId>  
  6.       <artifactId>maven-dependency-plugin</artifactId>  
  7.       <executions>  
  8.         <execution>  
  9.           <id>copy-dependencies</id>  
  10.           <phase>package</phase>  
  11.           <goals>  
  12.             <goal>copy-dependencies</goal>  
  13.           </goals>  
  14.           <configuration>  
  15.             <outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>  
  16.             <overWriteReleases>false</overWriteReleases>  
  17.             <overWriteSnapshots>true</overWriteSnapshots>  
  18.             <excludeTransitive>true</excludeTransitive>  
  19.           </configuration>  
  20.         </execution>  
  21.       </executions>  
  22.     </plugin>  
  23.   </plugins>  
  24. </build>  
  25. [...]  
  26. project>  

实际中,我们会一般的在pom中设置好我们这个OSGI环境所需要的一些bundles(插件),然后设置好outputDirectory(输出目录)假设是${project.build.directory},这个就是指代的这个工程下的target目录,然后用maven的命令:maven package来进行构建。构建完毕后一个符合我们自己需要的OSGI taget platform就设置好了。当然在一些最基础的OSGI核心bundle(比如org.eclipse.osgi)你就没必要再去以这种方式构建到target下了,因为你下下来一个eclipseIDE后,它里面就包含了一些基本的OSGI核心包(eclipse就是一个OSGI产品),至于在POM中配置dependecies的方式来配置那些需要的bundles,那这些bundle来至哪里呢,这个可以参考我以前的博客中写过得利用pax来进行这项OSGI bundle的构建工作。

<o:p> </o:p>

剩下来的步骤就是要把我们eclipse IDE的工作环境设到我们之前做好的这个OSGI bundles集合上来了。

首先在我们已经构建dependences集合的工程里面创建一个Target definition



先选择New一个Target definition

<o:p> </o:p>

父文件夹选择我们的放了dependences的工程目录,设置好target配置文件的文件名后,点击完成,这样一个target definition就建好了。然后对其做些配置

<o:p>
</o:p>

如果你已经有一个基础的eclipse环境(实际上就是个基础的OSGI环境),那么就在Target Location中将这个Location设置进来,此外再将我们刚才构建的我们自需要的OSGI环境设置在Additional Locations里面,最后保存下这个文件,再点击右上角的Set as Target Platform,那么我们的eclipse就可以立刻切换到我们自定义的OSGI开发环境中去了。

<o:p> </o:p>


总结:利用
maven插件以及eclipsetarget platform的结合,来构建一个我们自需要的OSGI环境,然后实现IDEtarget platform在这个target上的自由切换,有利于统一管理我们的OSGI开发平台环境,对开发中要用到的bundles进行了有效的积累和管理。
分享到:
评论
3 楼 yefeng 2008-08-01  
图看不到,LZ,
2 楼 onlydo 2008-07-28  
图看不到。。。
1 楼 phoenixup 2007-10-22  
JMX已经完败给OSGI了~~收藏了~
另外!很好,很强大~

相关推荐

Global site tag (gtag.js) - Google Analytics