问题
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