Java.lang.LinkageError when using JGit and Jsch to develop an Eclipse plugin

I am trying to develop an Eclipse plugin. This plugin uses jgit for accecc git repositories via ssh with ubuntu username and password. ( Clone git repository via ssh with username and password Java ). Using jgit on this with NetbBeans works just fine. Without problems, he can clone, complete and promote projects. However, when I move the same piece of code in the Eclipse jsch of the jgit and jsch plugin, I added to the project conflicts. If I delete the one that I added, I cannot compile the code (I need to import com.jcraft.jsch.Session into the class). On the other hand, if it is added, I have 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 The version of Eclipse 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 
0
source share
1 answer

Most likely, LinkageError occurs because there are two versions of the com.jcraft.jsch.Session class (and other classes from JSch). One of the built-in libraries in your kit, the other with the com.jcraft.jsch package, which is most likely present in your OSGi environment.

Do not put JSch in your package path. JSch classes from your bundle-class path will collide with the JSch package “outside”.

Use Require-Bundle or Import-Package to declare a dependency. For instance:

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

Source: https://habr.com/ru/post/1203046/


All Articles