子在川上曰

  逝者如斯夫不舍昼夜
随笔 - 71, 文章 - 0, 评论 - 915, 引用 - 0
数据加载中……

Eclipse插件及RCP开发中的第三方库的设置

文/陈刚 from www.chengang.com.cn at 2005-12-14
 
  很多人在开发RCP时,发现开发时都没问题,但导出成包时却报找不到第三方库中类的错误。主要原因就是没有将第三方库配置好。现在我给出一个实现项目的配置为示例,以供参考。
 
  环境:Eclipse3.2M3 一个RCP的实际项目,插件项目同样适用此方法
  
一、最关键的就是plugin.xml和MANIFEST.MF
  所有界面上的最后操作,结果都是保存在这两个文件中。注意:“.classpath”文件只是开发时对引用第三库有用,打包发行之后它的作用就没有了,还得靠plugin.xml和MANIFEST.MF。
 
1、plugin.xml文件
<?xml version="1.0" encoding="GB2312"?>
<?eclipse version="3.0"?>
<plugin>
   <extension
         id="AdminConsole"
         point="org.eclipse.core.runtime.applications">
        <application>
            <run class="com.wxxr.management.admin.console.AdminConsole"/>
        </application>
   </extension>
 
   <extension id="AdminConsole" point="org.eclipse.core.runtime.products">
  <product name="%productName" application="com.wxxr.management.admin.console.AdminConsole">
   <property name="appName" value="%swtAppName"/>
   <property name="windowImages" value="icons/eclipse.gif,icons/eclipse32.gif"/>
   <property name="aboutText" value="%aboutText"/>
   <property name="aboutImage" value="icons/eclipse_lg.gif"/>
   <property name="windowImages" value="icons/alt16.gif,icons/eclipse.gif"/>
  </product>
   </extension>
  
   <extension
      point="org.eclipse.ui.perspectives">
      <perspective
            class="com.wxxr.management.admin.console.monitor.MonitorPerspective"
            name="%perspectiveName"
            id="com.wxxr.management.admin.console.monitor.MonitorPerspective"/>
      <perspective
            class="com.wxxr.management.admin.console.configure.ConfigurePerspective"
            name="%configurePerspectiveName"
            id="com.wxxr.management.admin.console.configure.ConfigurePerspective"/>
      <perspective
            class="com.wxxr.management.admin.console.jmx.JMXPerspective"
            name="%jmxPerspectiveName"
            id="com.wxxr.management.admin.console.jmx.JMXPerspective"/>
   </extension>
 <extension
   point="org.eclipse.ui.editors">
   <editor
   name="事件列表"
   icon="icons/alt16.gif"
   class="com.wxxr.management.admin.console.log.ui.LogEditor"
   id="com.wxxr.management.admin.console.log.ui.LogEditor">
   </editor>
   <editor
   name="地图"
   icon="icons/map_view.gif"
   class="com.wxxr.management.admin.console.map.MapEditor"
   id="com.wxxr.management.admin.console.map.MapEditor">
   </editor>
 </extension>
   <extension
         point="org.eclipse.ui.views">
      <category
            id="com.wxxr.management.admin.console.monitor.view"
            name="%views.category.name"/>
      <view
            id="com.wxxr.management.admin.console.navigator.ui.StationExploreView"
            name="工作站"
            icon="icons/eclipse.gif"
            class="com.wxxr.management.admin.console.navigator.ui.StationExploreView"
            category="com.wxxr.management.admin.console.monitor.view"/>
      <view
            name="事件细节"
            icon="icons/eclipse.gif"
            category="com.wxxr.management.admin.console.monitor.view"
            class="com.wxxr.management.admin.console.monitor.eventview.EventDetailView"
            id="com.wxxr.management.admin.console.monitor.eventview.EventDetailView" />
      <view
            name="事件统计"
            icon="icons/eclipse.gif"
            category="com.wxxr.management.admin.console.monitor.view"
            class="com.wxxr.management.admin.console.monitor.view.SystemEventStatisticsView"
            id="com.wxxr.management.admin.console.monitor.view.SystemEventStatisticsView" />
      <view
            name="紧急事件处理"
            icon="icons/eclipse.gif"
            category="com.wxxr.management.admin.console.monitor.view"
            class="com.wxxr.management.admin.console.emergency.ui.EmergencyEventReceiverView"
            id="com.wxxr.management.admin.console.emergency.ui.EmergencyEventReceiverView" />
      <category
            id="com.wxxr.management.admin.console.jmx.view"
            name="%views.category.name"/>
      <view
            name="JMX Connections"
            icon="icons/eclipse.gif"
            category="com.wxxr.management.admin.console.jmx.view"
            class="com.wxxr.management.admin.console.jmx.ui.JMXExploreView"
            id="com.wxxr.management.admin.console.jmx.ui.JMXExploreView" />
      <view
            name="JMX Attributes View"
            icon="icons/eclipse.gif"
            category="com.wxxr.management.admin.console.jmx.view"
            class="com.wxxr.management.admin.console.jmx.ui.AttributesView"
            id="com.wxxr.management.admin.console.jmx.ui.AttributesView" />
      <view
            name="JMX Operations View"
            icon="icons/eclipse.gif"
            category="com.wxxr.management.admin.console.jmx.view"
            class="com.wxxr.management.admin.console.jmx.ui.OperationsView"
            id="com.wxxr.management.admin.console.jmx.ui.OperationsView" />
      <view
            name="JMX MBean View"
            icon="icons/eclipse.gif"
            category="com.wxxr.management.admin.console.jmx.view"
            class="com.wxxr.management.admin.console.jmx.ui.MBeanView"
            id="com.wxxr.management.admin.console.jmx.ui.MBeanView" />
   </extension>
   <extension
         id="AdminConsole"
         point="org.eclipse.core.runtime.products">
      <product
            application="com.wxxr.management.admin.console.AdminConsole"
            name="AdminConsole"/>
   </extension>
  
</plugin>
  
2、META-INF\MANIFEST.MF文件
注意:
(1)这里require-bundle定义了项目依赖的插件。
(2)Bundle-ClassPath定义了引用的第三方库,别忘了把AdminConolse项目自己console.jar加进去,否则连自己项目里的类都会找不到。
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: com.wxxr.management.admin.console; singleton:=true
Bundle-Version: 1.0.0
Bundle-Activator: com.wxxr.management.admin.console.AdminConsolePlugin
Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 org.eclipse.core.resources,
 org.eclipse.gef,
 org.eclipse.ui.forms,
 org.eclipse.ui.console
Eclipse-AutoStart: true
Bundle-Vendor: %providerName
Bundle-ClassPath: console.jar,
 lib/commons-codec-1.3.jar,
 lib/jboss.jar,
 lib/jbossall-client.jar,
 lib/jboss-jmx.jar,
 lib/jboss-system.jar,
 lib/log4j-1.2.8.jar,
 lib/wxxr-common-1.0-b1.jar,
 lib/wxxr-common-jboss-1.0-b1.jar,
 lib/wxxr-db-persistence-1.0-b1.jar,
 lib/wxxr-jboss-controller-1.0-b1.jar,
 lib/wxxr-jboss-workstation-1.0-b1.jar,
 lib/wxxr-remoting-1.0-b1.jar,
 lib/wxxr-security-1.0-b1.jar,
 lib/xerces-2.6.2.jar,
 lib/xmlParserAPIs-2.2.1.jar,
 lib/xmlrpc-2.0.jar
 
3、build.properties文件。这个文件主要是用Eclipse导出包的时候用。
source.console.jar = src/
output.console.jar = bin/
bin.includes = plugin.xml,\
     *.jar,\
               console.jar, \
               plugin.properties
              
pluginName = Admin Console Plug-in
providerName = WXXR.com.cn
perspectiveName = Admin Console
configurePerspectiveName= Configure
jmxPerspectiveName= JMX Console
               
jars.extra.classpath = lib/commons-codec-1.3.jar,\
                       lib/jboss.jar,\
                       lib/jbossall-client.jar,\
                       lib/jboss-jmx.jar,\
                       lib/jboss-system.jar,\
                       lib/log4j-1.2.8.jar,\
                       lib/wxxr-common-1.0-b1.jar,\
                       lib/wxxr-common-jboss-1.0-b1.jar,\
                       lib/wxxr-db-persistence-1.0-b1.jar,\
                       lib/wxxr-jboss-controller-1.0-b1.jar,\
                       lib/wxxr-jboss-workstation-1.0-b1.jar,\
                       lib/wxxr-security-1.0-b1.jar,\
                       lib/wxxr-remoting-1.0-b1.jar,\
                       lib/xerces-2.6.2.jar,\
                       lib/xmlParserAPIs-2.2.1.jar,\
                       lib/xmlrpc-2.0.jar
 
4、plugin.properties,这个放一些上面几个文件用到的变量。
pluginName= WXXR Admin Console
providerName= wxxr.com.cn
 
productName= WXXR SMS Operation Platform
appName= WXXR Admin Console
perspectives.browser.name= WXXR Admin Console
views.category.name= WXXR Admin Console
views.browser.name= Browser
views.history.name= History
views.stationexplore.name= Stations
views.tasklist.name= Task List
views.loglist.name= Workstation Monitor
monitor.message.detail=Monitor Message Detail
monitor.message.statistics=????
 
swtAppName= AdminConsole
aboutText= WXXR Admin Console \n\n\
(c) Copyright WXXR Ltd. and others 2003, 2004.  All rights reserved.\n\
Visit http://www.wxxr.com.cn
 
 
二、图形方式
 有时直接编辑plugin.xml等文件容易出错(全角空格什么的),那么可以用图形编辑方式来,不过最后结果还是反映到plugin.xml等文件中的。我把plugin.xml打开,然后一个项一个项的把图截下来,以供大家参考。
 
1134538761302_5236.gif 

1134538769117_7853.gif 

1134538790864_4652.gif 

1134538806626_1515.gif 

1134538814862_3413.gif 

 
 这个界面是build.properties配置的反映
1134538823973_7531.gif 

 
 最好在项目属性的库用引项的效果如下:
1134535421290_7544.gif 


 
作者简介

陈刚,广西桂林人,著作有《Eclipse从入门到精通》
您可以通过其博客了解更多信息和文章:http://www.chenGang.com.cn

posted on 2006-03-07 14:48 陈刚 阅读(2822) 评论(0)  编辑  收藏 所属分类: Eclipse


只有注册用户登录后才能发表评论。


网站导航: