将一个普通 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  工程的时候选择解压。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值