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

在Eclipse插件项目中引用第三方JAR包 空指针异常解决

阅读更多
I often get the question "How to add a third party JAR-file to my Eclipse plugin". It is not that tricky, but neither that obvious. Two solutions has been posted on the Eclipse newslists, but it can be quite hard to find it as the sheer number of posts is overhelming.

Here is two ways of doing it:
1. Turn the JAR-file(s) into plugin(s)
This is probably the simplest solution, but maybe not always achieving the desired granularity though. "Use New" -> "Project" -> "Plug-in Development" -> "Plug-in from existing JAR Archive". That will turn the JAR-file into a single JAR-plugin. Check that all required packages are re-exported.

2. Include the JAR-file(s) in the plugin in question:



Use the "Import" -> "File System" to import the JAR-file(s) into your plugin project. E.g. '/lib' directory

Then use "Add..." to add the JAR-file(s) to the classpath section of the Manifest/plugin.xml runtime tab.

Press "New..." to add "." library back to the the classpath (without quotes).

Check that the binary build exports the new JAR-file(s) on the Build tab.

Press save, important for the changes to come through.

Select the project in question in the package explorer view, right click and select "PDE Tools" -> "Update classpath". This will add the newly added JAR-file(s) to the project´s classpath.
When you are in the process of exporting the plugin make shure you do not package the plugin as "individual JAR archives", Eclipse cannot load JARs from within JARs, yet.
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.0"?>
<plugin
   id="colimas_plugin"
   name="Colimas_plugin Plug-in"
   version="1.0.0"
   provider-name="nova"
   class="colimas_plugin.Colimas_pluginPlugin">

   <runtime>
      <library name="colimas_plugin.jar">
         <export name="*"/>
      </library>
      <library name="lib/activation.jar">
         <export name="*"/>
      </library>
      <library name="lib/axis.jar">
         <export name="*"/>
      </library>
      <library name="lib/commons-beanutils.jar">
         <export name="*"/>
      </library>
      <library name="lib/commons-discovery-0.2.jar">
         <export name="*"/>
      </library>
      <library name="lib/commons-logging-1.0.4.jar">
         <export name="*"/>
      </library>
      <library name="lib/jaxrpc.jar">
         <export name="*"/>
      </library>
      <library name="lib/xalan.jar">
         <export name="*"/>
      </library>
      <library name="lib/xerces.jar">
         <export name="*"/>
      </library>
      <library name="lib/saaj.jar">
         <export name="*"/>
      </library>
      <library name="lib/mail.jar">
         <export name="*"/>
      </library>
   </runtime>

   <requires>
      <import plugin="org.eclipse.ui"/>
      <import plugin="org.eclipse.core.runtime"/>
   </requires>

   <extension
         point="org.eclipse.ui.actionSets">
      <actionSet
            label="Sample Action Set"
            visible="true"
            id="colimas_plugin.actionSet">
         <menu
               label="Sample &amp;Menu"
               id="sampleMenu">
            <separator
                  name="sampleGroup">
            </separator>
         </menu>
         <action
               label="&amp;Sample Action"
               icon="icons/sample.gif"
               class="colimas_plugin.actions.SampleAction"
               tooltip="Hello, Eclipse world"
               menubarPath="sampleMenu/sampleGroup"
               toolbarPath="sampleGroup"
               id="colimas_plugin.actions.SampleAction">
         </action>
      </actionSet>
   </extension>

</plugin>




以上是本人转载的他人的文章,最后发现根本不需要上述操作,上述操作根据没用

具体方法参见附件中的PDF文档。很详细
  • rcp.zip (664.7 KB)
  • 下载次数: 397
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics