在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 &Menu"
id="sampleMenu">
<separator
name="sampleGroup">
</separator>
</menu>
<action
label="&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>



[size=x-large][color=red]
以上是本人转载的他人的文章,最后发现根本不需要上述操作,上述操作根据没用

具体方法参见附件中的PDF文档。很详细[/color][/size]
FindBugs 是一个静态分析工具,它检查类或者 JAR 文件,将字节码与一组缺陷模式进行对比以发现可能的问题。有了静态分析工具,就可以在不实际运行程序的情况对软件进行分析。不是通过分析类文件的形式或结构来确定程序的意图,而是通常使用 Visitor 模式(请参阅 参考资料)。图 1 显示了分析一个匿名项目的结果(为防止可怕的犯罪,这里不给出它的名字):   在FindBugs的GUI,需要先选择待扫描的.class文件(FindBugs其实就是对编译后的class进行扫描,藉以发现一些隐藏的bug。)。如果你拥有这些.class档对应的源文件,可把这些.java文件再选上,这样便可以从稍后得出的报告快捷的定位到出问题的代码上面。此外,还可以选上工程所使用的library,这样似乎可以帮助FindBugs做一些高阶的检查,藉以发现一些更深层的bug。   选定了以上各项后,便可以开始检测了。检测的过程可能会花好几分钟,具体视工程的规模而定。检测完毕可生成一份详细的报告,藉由这份报告,可以发现许多代码间潜在的bug。比较典型的,如引用空指针(null pointer dereference), 特定的资源(db connection)未关闭,等等。如果用人工检查的方式,这些bug可能很难才会被发现,或许永远也无法发现,直到运行时发作…当除掉了这些典型的(classic) bug后,可以确信的是,我们的系统稳定度将会上一个新的台阶。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值