java.lang.LinkageError while using JGit and Jsch for Eclipse plugin development

狂风中的少年 提交于 2020-01-06 09:05:40

问题


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

回答1:


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)"


来源:https://stackoverflow.com/questions/26102649/java-lang-linkageerror-while-using-jgit-and-jsch-for-eclipse-plugin-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!