将一个普通 JAR 文件打包为 plugin 的一个问题

最近一直在使用 commons-httpclient-3.1.jar 模拟 HTTP client 端,但是该 jar 只是一个普通 jar 文件,不是一个 plugin, 而我们的需求是既要能在 Eclipse 中,也能在命令行中使用(即将导出的plugin jar 加入到 classpath 中),因此需要将其打包成一个 plugin。

我用 Eclipse 中的 "Plug-in from existing JAR archives" 来打包,其中有一个选项 :Unzip the JAR archives into the project, 其默认是选中,即将 commons-httpclient-3.1.jar 解压到项目中。本来想,如果不解压会显得更简洁一些,但是却遇到了问题:在用 export 导出为plugin jar 并在命令行中使用的时候,找不到所需的类,而在 MANIFEST.MF 文件中确实将所有的包都 export 了。想了半天也没弄明白为什么解压和不解压有如此差别。

最后在 Eclipse 的帮助文档中找到了答案 :

Unzipping JARs
Whether the JARs should be zipped or unzipped depends on how you want to package the plug-in. If the plug-in is to be shipped as a single JAR - which is the recommended format as of Eclipse 3.1 - the individual JAR archives should be unzipped. If the plug-in is to be shipped as a flat directory, then the individual JAR archives should be left intact.

也就是说如果要把打包的 plugin 导出为一个独立的 JAR 文件使用的话,必须在建 plugin  工程的时候选择解压。

posted @ 2009-05-31 17:42  coding_rabbit  阅读(135)  评论(0编辑  收藏  举报