Search code examples
javajarclasspatheclipse-luna

Getting NoClassDefFoundError while using JGit in eclipse luna


I recently download eclipse luna and installed the EGit plugin through Eclipse. I can see the download jar files in eclipse/plugins folder. I then added the JGit jar file to my build path and I can see the class files inside my Referenced Libraries folder.
However, when I run the project I get the following error

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.eclipse.jgit.util.FS.<clinit>(FS.java:112)
at org.eclipse.jgit.lib.BaseRepositoryBuilder.setupWorkTree(BaseRepositoryBuilder.java:620)
at org.eclipse.jgit.lib.BaseRepositoryBuilder.setup(BaseRepositoryBuilder.java:556)
at org.eclipse.jgit.storage.file.FileRepositoryBuilder.build(FileRepositoryBuilder.java:92)
at org.eclipse.jgit.storage.file.FileRepositoryBuilder.create(FileRepositoryBuilder.java:110)
at upload_gen.Launcher.main(Launcher.java:16)

Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 6 more

I googled the problem which said that it might be because my classpath doesn't include the jar file. But when I check the the classpath tab in "run | run configuration" it seems to be including the jar file. I also checked the .classpath file in the root folder which looks like this

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry exported="true" kind="lib" path="lib/org.eclipse.jgit_3.7.0.201502260915-r.jar"/>
<classpathentry kind="var" path="JGIT_JARS"/>
<classpathentry kind="output" path="bin"/>
</classpath>

I also tried adding the JGit jar file in the lib folder in the root of my project as you can see in the above .classpath file. In short, I tried adding the jar file externally as well as internally but I'm still getting the error. I also tried referencing the jar file using a class variable but that doesn't work either. Also there are no errors while compiling the project, getting error only when the project is run.


Solution

  • You probably need to add a slf4j jar to the libraries in Eclipse.