java.lang.LinkageError同时使用JGit和Jsch进行Eclipse插件开发 [英] java.lang.LinkageError while using JGit and Jsch for Eclipse plugin development

查看:350
本文介绍了java.lang.LinkageError同时使用JGit和Jsch进行Eclipse插件开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一个Eclipse插件。这个插件使用 jgit 来使用ubuntu用户名和密码来通过ssh来访问git存储库。 (通过ssh克隆git存储库,用户名和密码由Java )在NetbBeans中使用jgit工作很好。没有问题,它可以克隆,提交和推送项目。但是当我将相同的代码片段移动到jjit插件的Eclipse jsch中,并且我将jsch添加到项目冲突中。如果我删除了我添加的那个,那么我无法编译代码(我需要在一个类中导入com.jcraft.jsch.Session)。另一方面,如果添加了我有以下错误

  java.lang.LinkageError:
加载器约束违反:loader
(org / eclipse / osgi / internal / baseadaptor / DefaultClassLoader的实例)
以前启动加载名称为
com / jcraft / jsch / Session的不同类型

有没有办法摆脱这个混乱?



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



我的插件清单

  Manifest-Version:1.0 
Bundle-ManifestVersion:2
Bundle-Name:****
Bundle- SymbolicName:****; singleton:= true
Bundle-Version:1.1.0513
Bundle-Activator:****。Activator
需求包: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


解决方案

LinkageError最有可能发生,因为有两个版本的com.jcraft.jsch.Session(和JSch的其他类)。一个来自您的软件包中的嵌入式库,另一个来自可能存在于您的OSGi运行时的com.jcraft.jsch软件包。



不要把JSch放在你的bundle-classpath上。您的bundle-classpath中的JSch类将与外部的JSch bundle冲突。



使用 Require-Bundle Import-Package 来声明依赖关系。例如:

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


I am trying to develop an Eclipse plugin. This plugin uses jgit to accecc git repositories over ssh with ubuntu username and password. (Clone git repository over ssh with username and password by Java) Using jgit in this with NetbBeans works just fine. Without a problem it can clone, commit and push projects. However when I move the same code fragment into Eclipse jsch of jgit plugin and the jsch I've added to the project conflicts. If I remove the one I've I added then I cannot compile the code (I need to import com.jcraft.jsch.Session in a class). On the other hand, if it is added I've got the following error

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"

Is there a way out of this mess?

I am using jgit-3.2.0 and jsch-0.1.5.0 Eclipse version is Kepler.

My plugin manifest

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

解决方案

Most likely, the LinkageError occurs because there are two versions of class com.jcraft.jsch.Session (and other classes from JSch). One comes from the embedded library in your bundle, the other is provided by the com.jcraft.jsch bundle that is very likely present in your OSGi runtime.

Don't put JSch on your bundle-classpath. The JSch classes from your bundle-classpath will clash with the JSch bundle 'outside' .

Use Require-Bundle or Import-Package to declare the dependency. For example:

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

这篇关于java.lang.LinkageError同时使用JGit和Jsch进行Eclipse插件开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆