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

How to add 3rd party libraries into Eclipse RCP?

我正在使用 Eclipse RCP 编写一个 GUI,它将使用 Spring 框架相关项目,例如:

所以我的问题是如何优雅地添加这个依赖项? (Spring很久不支持osgi了,还有很多其他的方式很繁琐)

我找到了一个很好的解决方案来解决这个问题。它将使用以下技能:MavenEclipse Plugin

步骤是:

  • 首先写pom.xml里面包含你想要的依赖,例如:spring-websocket

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
    </dependency>
    
  • 然后,你需要下载所有的websocket jar,你需要使用maven命令来帮你完成:),所有的jar都在/目标 默认文件夹

    mvn dependency:copy-dependencies

    Note: maven will handle the dependency tree.

  • 接下来,在Eclipse中创建一个"Plug-in from Existing JAR Archives"项目并导入这些jar

    Note: Un-check the "Upzip the JAR archives into the project". (Or all jars will be decompressed into folder and files then stored in the project)

  • 最后,将此插件项目作为 依赖项 添加到您的主 RCP 项目中。您现在可以 write/run 您的 websocket 客户端了!

希望这是解决此问题的优雅方法。

有多种方法可以将 Maven 工件转换为 OSGi 包:

  1. Eclipse Bundle Recipes
  2. p2-maven-plugin 结合 Tycho 和 Nexus 存储库,您将拥有一个优雅的工具来将第三方依赖项添加到您的 Eclipse-RCP 项目。