构建一个在 Eclipse PDE 中使用的 jar?
我编写了一个使用第三方库的应用程序。然后,我使用 maven-assemble-plugin 将其打包为可执行 jar(生成一个包含所有依赖项的 jar,包括一些第三方 jar)。
接下来,我需要将此 jar 添加到 PDE 项目中,以便可以从 eclipse 启动它。但为了完成这项工作,我需要将一些第三方依赖项添加到我的 PDE 项目中,该项目已经位于打包的 jar 中。所以我得到了重复的依赖项。关于如何避免这种情况的任何想法?或者对描述如何正确完成此操作的文档提出建议?
I have written an application that use a third party library. I have then packaged this as an executable jar using the maven-assembly-plugin (producing a jar with all dependencies including some of the third-party jars).
Next I need to add this jar to a PDE project so it can be launched from eclipse. But to make this work I need to add some of the thirs-party dependencies to my PDE project which is already located in the packaged jar. So I get duplicated dependencies. Any ideas on how to avoid this? Or suggestion to documentation that describes how this is done properly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该构建一个 jar,这是一个 OSGi 包:因此它包含所需的带有插件 id 和版本号的 manifest.mf(这不会改变 jar 仍然可执行的事实)。请小心添加导出包选项,以使代码也可用于其他插件/捆绑包。
之后,您可以将此 jar 安装到 PDE 项目使用的目标平台中(在首选项中搜索目标平台),以便通过 ID 可用于其他插件(您可以将其添加为依赖项)。
这样,如果至少有一个插件需要您的 jar,它就会被加载,但不会被加载多次。
You should build a jar, that's an OSGi bundle: so it contains the required manifest.mf with a plug-in id and a version number (this does not change the fact, that the jar remains executable). Be careful to add the export-packages option to make the code available for other plug-ins/bundles as well.
After that you could install this jar into the target platform used by the PDE project (search for Target platform in the preferences), so it becomes available for other plug-ins by the ID (you could add it as a dependency).
This way, if at least one plug-in needs your jar, it gets loaded, but will not get loaded several times.
我认为将其他罐子包含在您的罐子中是很糟糕的做法。但如果您想保持这种方式,如何从一个构建中创建两个 jar:一个具有依赖项的完整 jar,一个在 PDE 中使用的简单 jar(只需在程序集插件中使用多次执行)
I think it is just plain bad practice to include the other jars in your jar. But if you want to keep it that way, how about creating two jars from one build: a full one with dependencies, and a simple one to use in PDE (just use multiple executions in the assembly plugin)
我现在使用 maven-bundle-plugin:
http ://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
构建捆绑包。但是我如何使用捆绑插件,以便它使用 maven- assembly-plugin 为 jar 构建创建 MANIFEST 文件,我使用它,如下所示:
I am now using the maven-bundle-plugin:
http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
to build a bundle. But how do I use the bundle plugin so it creates the MANIFEST file for the jar build with the maven-assembly-plugin, which I use like: