如何将外部 jar 添加到 eclipse rcp 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1227425/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:57:10  来源:igfitidea点击:

How can I add the external jar to the eclipse rcp application?

eclipseeclipse-rcp

提问by prabakaran ramu

I tried to add the apache vfs jar file as the runtime dependency. Even though it throws the below error:

我尝试将 apache vfs jar 文件添加为运行时依赖项。即使它抛出以下错误:

java.lang.ClassNotFoundException: org.apache.commons.vfs.VFS at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:489) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:405) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:393) at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at file_explorer.View.setInput(View.java:295) at file_explorer.View.initialize(View.java:130)

java.lang.ClassNotFoundException:org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:489) 处的 org.apache.commons.vfs.VFS 在 org.eclipse.osgi.internal.loader.BundleLoader.findClass (BundleLoader.java:405) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:393) at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319) at file_explorer.View.setInput(View.java:295) at file_explorer.View.initialize(View .java:130)

How can i resolve this, thanks in advance.

我该如何解决这个问题,提前致谢。

回答by Manuel Selva

The best way to include external Jar in Eclipse RCP application is to package it as a plugin and then use classic plugin dependency.

在 Eclipse RCP 应用程序中包含外部 Jar 的最佳方法是将其打包为插件,然后使用经典插件依赖项。

Just create a new plugin containing only your Jar. Then in the build tab of the manifest editor, add your jar to the classpath (at the bottom right) and export all its packages in this same runtime tab. Also be sure to check that you jar is checked in the Build tab.

只需创建一个仅包含您的 Jar 的新插件。然后在清单编辑器的构建选项卡中,将您的 jar 添加到类路径(在右下角)并在同一个运行时选项卡中导出它的所有包。还要确保在 Build 选项卡中检查您的 jar 是否已选中。

Nevertheless you should be able to use the jar in a Given plugin source code if you only add it to the classpath as I mentioned previously.

尽管如此,如果您只将它添加到我之前提到的类路径中,您应该能够在给定的插件源代码中使用该 jar。

Because some other of your plugins may be interested in using the vfs jar and for separtion of concerns matter I think you should wrap it in its own plugin

因为您的其他一些插件可能对使用 vfs jar 感兴趣,并且为了分离问题,我认为您应该将其包装在自己的插件中

回答by Jaknap Ramuk

If you are looking for adding the required jars to your project classpath.Add the required files to lib directory in the project structure.Then from project click the 'run time' tab of plugin.xml and add the required jars from the lib directory to the project classpath.

如果您正在寻找将所需的 jar 添加到您的项目类路径中。将所需的文件添加到项目结构中的 lib 目录。然后从项目中单击 plugin.xml 的“运行时”选项卡并将所需的 jar 从 lib 目录添加到项目类路径。

回答by ILX

The easiest way is to find bundle in an existing OSGI bundle repository.

最简单的方法是在现有的 OSGI 包存储库中查找包。

http://bundles.osgi.org/Main/Repository
http://www.springsource.com/repository/app/
http://www.eclipse.org/orbit/
http://www.knopflerfish.org/repo/index.html

springsource repo contains apache VFS bundle

springsource repo 包含 apache VFS 包

Then you need to add the bundle to the target platform (or just copy it to the dropins folder)

然后你需要将 bundle 添加到目标平台(或者只是将其复制到 dropins 文件夹)

In order to properly install bundle into a newer version of eclipse you should use an existing p2 repository and install bundle from p2 repository into your runtime platform. There are two ways: you could use existing one (like orbit p2 repo), or you could create your own using p2 publisher as described at https://docs.sonatype.org/display/TYCHO/How+to+make+existing+OSGi+bundles+consumable+by+Tycho

为了将 bundle 正确安装到较新版本的 eclipse 中,您应该使用现有的 p2 存储库并将 bundle 从 p2 存储库安装到您的运行时平台中。有两种方法:您可以使用现有的一种(如轨道 p2 回购),或者您可以使用 p2 发布者创建自己的,如https://docs.sonatype.org/display/TYCHO/How+to+make+existing 所述+OSGi+捆绑包+消耗品+by+第谷

回答by Dave Pateral

Eclipse RCP is an OSGi environment which extends the Java dependency model, so you can't simply take a jarfile and hope it works. To use an external jar, you have to build it to a plugin first, which p2-maven-plugincan help, you can follow the readme document.

Eclipse RCP 是一个 OSGi 环境,它扩展了 Java 依赖模型,因此您不能简单地获取一个jar文件并希望它可以工作。要使用外部jar,你必须先将其构建为插件,p2-maven-plugin可以提供帮助,您可以按照readme 文档进行操作。

With the plugin ready, you should install the plugin and add it to MANIFEST.MF. Then restart Eclipse to make the plugin work.

插件准备好后,您应该安装插件并将其添加到MANIFEST.MF. 然后重新启动 Eclipse 以使插件工作。

A more easily way, you needn't install the plugin, just follow(but build the jar):

更简单的方法,您不需要安装插件,只需按照(但构建 jar):

  1. go to plugin.xml-> Runtimetab;
  2. click Addat the classpathsection, then add the plugin to classpath;
  3. make sure there is .path in the text area, otherwise Newit.
  1. 转到plugin.xml->Runtime标签;
  2. 单击Addclasspath部分,然后将插件添加到类路径;
  3. 确保.文本区域中有路径,否则New