0

I'm trying to use DigestUtils class from org.apache.commons.codec.digest and I imported it in java like this:

import org.apache.commons.codec.digest.DigestUtils;

When I run it in Eclipse, it works. But when I try to run it from Command Prompt (with "java Simhash"), I'm getting this:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/digest/DigestUtils
    at Simhash.main(Simhash.java:17)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.digest.DigestUtils
    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)
    ... 1 more

I'm a total Java-newbie. I downloaded commons-codec-1.10.jar file, put it in my project folder and imported it with Build Path -> Configure Build Path -> Add External JARs...

Any idea?

XploD
  • 367
  • 3
  • 15

2 Answers2

1

Add the JAR file to your command line runtime classpath

java -cp commons-codec-1.10.jar;. Simhash

This should also simply run directly from Eclipse as youve already added the file to the classpath.

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • thanks, this solved my problem. I assumed that it was due to linking, but wasn't sure how to do it. yes, it works in Eclipse, but my program reads from stdin and I have to pass a file to stdin. I think that this can't be done in Eclipse so I have to run it from CMD to be able to call it as "java Simhash < input.txt" – XploD Apr 17 '15 at 14:59
1

You need to add class path in java command as argument. Check java documentation for more information.

java -classpath DigestUtils.jar:. TestClass
chilltouch
  • 281
  • 2
  • 10