Greetings,
I'm playing around with mahout, I've written a basic java class which imports some of the libraries. It seems my classpath is correct when compiling, I get no errors or complaints at all.
However when I run the compiled class I get an exception saying...
Exception in thread "main" java.lang.NoClassDefF开发者_开发技巧oundError: Test
Caused by: java.lang.ClassNotFoundException: Test
My guess is that .
is not on your classpath. For example, you might be compiling with:
javac -cp foo.jar:bar.jar Test.java
but then to run the code you'd need
java -cp foo.jar:bar.jar:. Test
The code that you're compiling doesn't need to be on the classpath as you're providing the code (so there's nothing to find) - that's why it manages to compile but not run.
That's only a guess, of course - if you could post the commands you're using to compile and run the code, that would help.
I'm now getting an error saying
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
You're missing slf4j-api.jar
on your class path. With SLF4J, you always need slf4j-api.jar
and another jar to bind a logging framework. And actually, if you don't care about logging, use slf4j-nop.jar
instead of slf4j-log12.jar
.
Update: Mahout seems to be available in Maven central repository so using Maven could ease the class path setup process. And if you're not into learning Maven, consider using MOP which is a command line launcher to run Java stuff that can transparently download Maven artifacts and their dependencies and setup your classpath.
Compile time classpath sounds right; runtime classpath is wrong.
From the javadocs for that class:
Thrown if the Java Virtual Machine or a ClassLoader instance tries to load in the definition of a class (as part of a normal method call or as part of creating a new instance using the new expression) and no definition of the class could be found.
The searched-for class definition existed when the currently executing class was compiled, but the definition can no longer be found.
Do you see a Test.class file in the current directory? Maybe you compiled it to another path by mistake.
If you are using Mahout, be aware that after you build it with Maven, it will generate "*.job" files in the target/ directory, which contain all dependencies packaged together. It is just a .jar file.
精彩评论