简体   繁体   English

如何将第3方库添加到Eclipse RCP中?

[英]How to add 3rd party libraries into Eclipse RCP?

I'm using Eclipse RCP to write a GUI which would use Spring framework related projects, such as: 我正在使用Eclipse RCP编写GUI,该GUI将使用与Spring框架相关的项目,例如:

  • Spring WebSocket client Spring WebSocket客户端
  • Spring Web Client Spring Web客户端

So my question is how to add this dependencies elegantly ? 所以我的问题是如何优雅地添加此依赖项? (Spring does not support osgi for a long time, there are many other ways which are very complicated and tedious) (Spring长期以来不支持osgi,还有许多其他方法非常繁琐而繁琐)

I've found a good Solution to solve this problem. 我找到了一个很好的解决方案来解决这个问题。 It will use following skills: Maven , Eclipse Plugin 它将使用以下技能: MavenEclipse插件

The steps are: 这些步骤是:

  • first, write the pom.xml which contains the dependencies you want, for example: spring-websocket 首先,编写包含所需依赖项的pom.xml ,例如:spring-websocket

     <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> 
  • then, you need to download all websocket jars, you need to use maven command to help you to do that :), the jars are all in /target folder by default 然后,您需要下载所有websocket jar,需要使用maven命令来帮助您完成此操作:),这些jar默认情况下都位于/ target文件夹中

    mvn dependency:copy-dependencies

    Note: maven will handle the dependency tree. 注意:maven将处理依赖关系树。

  • next, in Eclipse create a "Plug-in from Existing JAR Archives" project and import these jars 接下来,在Eclipse中创建一个“来自现有JAR存档的插件”项目并导入这些jar

    Note: Un-check the "Upzip the JAR archives into the project". 注意:取消选中“将JAR归档文件压缩到项目中”。 (Or all jars will be decompressed into folder and files then stored in the project) (或者将所有的jar文件解压缩到文件夹和文件中,然后存储在项目中)

  • finally, add this plugin project in your main RCP project as a dependency . 最后,将此插件项目作为依赖项添加到您的主RCP项目中。 And you can write/run your websocket client now! 您现在可以编写/运行您的websocket客户端!

Hope this is an elegant way to solve this problem. 希望这是解决此问题的一种优雅方法。

There are different ways to convert maven artifacts to OSGi bundles: 有多种方法可以将Maven工件转换为OSGi捆绑包:

  1. Eclipse Bundle Recipes Eclipse捆绑食谱
  2. p2-maven-plugin in combination with a Tycho and a Nexus repository you have a elegant tooling to add thirdparty dependencies to your Eclipse-RCP project. p2-maven-plugin与Tycho和Nexus存储库结合使用,您可以使用精美的工具将第三方依赖项添加到Eclipse-RCP项目中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM