Home > Mobile >  Why am I getting the "Class Not Found" error in Java?
Why am I getting the "Class Not Found" error in Java?

Time:09-24

Upon trying to run my code, I get this problem:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/digest/DigestUtils
    at primjer.ZastitniKodIzracun.main(ZastitniKodIzracun.java:67)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.digest.DigestUtils
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 1 more

If I understood well, this could be due to an error in naming/saving the files which compose the project, but I'm not sure what's the problem - the name of the Java source code file corresponds to the text of the "public class" line in the code (ZastitniKodIzracun.java). I'm working in Eclipse. The beginning of the code goes like this:

import java.io.FileInputStream;
import java.security.Key;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.Signature;
import java.util.Date;
import java.text.SimpleDateFormat;
import org.apache.commons.codec.digest.DigestUtils;

CodePudding user response:

java.lang.ClassNotFoundException: 

Most of the times this happens when the required library (and all of its dependencies) is not in classpath for runtime. Make sure the appropriate version of the dependency lib is packaged (or) available for runtime (not just compile time).

  • Related