【问题标题】:java.lang.LinkageError while using JGit and Jsch for Eclipse plugin development使用 JGit 和 Jsch 进行 Eclipse 插件开发时出现 java.lang.LinkageError
【发布时间】:2014-11-24 00:11:58
【问题描述】:

我正在尝试开发一个 Eclipse 插件。此插件使用 jgit 通过 ssh 使用 ubuntu 用户名和密码来访问 git 存储库。 (Clone git repository over ssh with username and password by Java) 在此与 NetbBeans 一起使用 jgit 效果很好。它可以毫无问题地克隆、提交和推送项目。但是,当我将相同的代码片段移动到 jgit 插件的 Eclipse jsch 中时,我添加到项目中的 jsch 发生冲突。如果我删除了我添加的那个,那么我无法编译代码(我需要在一个类中导入 com.jcraft.jsch.Session)。另一方面,如果添加它,则会出现以下错误

java.lang.LinkageError: 
  loader constraint violation: loader 
    (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader)
    previously initiated loading for a different type with name 
    "com/jcraft/jsch/Session"

有办法摆脱这种混乱吗?

我正在使用 jgit-3.2.0 和 jsch-0.1.5.0 Eclipse 版本是 Kepler。

我的插件清单

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ****
Bundle-SymbolicName: ****;singleton:=true
Bundle-Version: 1.1.0513
Bundle-Activator: ****.Activator
Require-Bundle: org.eclipse.ui,
 org.eclipse.core.runtime,
 org.eclipse.ui.browser;bundle-version="3.4.100",
 org.eclipse.core.resources;bundle-version="3.8.100",
 org.eclipse.ui.ide;bundle-version="3.9.0",
 org.eclipse.jdt.core;bundle-version="3.9.0",
 org.eclipse.core.filesystem;bundle-version="1.4.0",
 org.eclipse.team.core;bundle-version="3.7.0",
 org.eclipse.jgit;bundle-version="3.2.0",
 org.eclipse.jdt.launching;bundle-version="3.7.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .,
 lib/commons-io-2.4.jar,
 lib/zip4j_1.3.2.jar,
 lib/jsch-0.1.50.jar

【问题讨论】:

    标签: eclipse eclipse-plugin osgi osgi-bundle linkageerror


    【解决方案1】:

    发生 LinkageError 很可能是因为 com.jcraft.jsch.Session 类(以及 JSch 中的其他类)有两个版本。一个来自您的包中的嵌入式库,另一个由 com.jcraft.jsch 包提供,它很可能存在于您的 OSGi 运行时中。

    不要将 JSch 放在你的 bundle-classpath 中。您的 bundle-classpath 中的 JSch 类将与 JSch bundle 'outside' 发生冲突。

    使用Require-BundleImport-Package 来声明依赖。例如:

    Require-Bundle: com.jcraft.jsch;bundle-version="[0.1.50,0.2.0)"
    

    【讨论】:

    • 不要使用 Require-Bundle。使用 Import-Package。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-25
    • 2014-11-26
    • 2011-04-09
    • 1970-01-01
    • 1970-01-01
    • 2011-09-06
    相关资源
    最近更新 更多