伏地魔运行时错误

时间:2013-10-11 12:00:42

标签: java voldemort

我正在尝试运行可以在Voldemort下载中找到的客户端示例。

我的路径位置: /home/voldemart/voldemort-1.3.0/clientjava

我编译了代码

javac -classpath ../dist/voldemort-1.3.0.jar ClientVoldemort.java

没有出现错误。但是当我尝试按如下方式运行代码时:

java -classpath ../dist/voldemort-1.3.0.jar ClientVoldemort
Exception in thread "main" java.lang.NoClassDefFoundError: ClientVoldemort
Caused by: java.lang.ClassNotFoundException: ClientVoldemort
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

ClientExample code Given below.

package voldemort.examples;
import voldemort.client.ClientConfig;
import voldemort.client.SocketStoreClientFactory;
import voldemort.client.StoreClient;
import voldemort.client.StoreClientFactory;
import voldemort.versioning.Versioned;
public class ClientExample {
public static void main(String[] args) {
String bootstrapUrl = "tcp://localhost:6666";
StoreClientFactory factory = new SocketStoreClientFactory(new ClientConfig().setBootstrapUrls(bootstrapUrl));
StoreClient<String, String> client = factory.getStoreClient("my_store_name");
Versioned<String> version = client.get("some_key");
version.setObject("new_value");
client.put("some_key", version);
}
}

2 个答案:

答案 0 :(得分:0)

看来JVM没有在预期的位置找到类,即相对于当前目录的voldemort/examples

需要进行一些调整

  • 将当前目录添加到类路径
  • 将课程限定为voldemort.examples.ClientVoldemort

将课程移至voldemort/examples并使用

编译&amp;运行命令:

javac -cp ../dist/voldemort-1.3.0.jar voldemort/examples/*.java
java -cp ../dist/voldemort-1.3.0.jar:. voldemort.examples.ClientVoldemort

注意:当使用-classpath-cp标志时,当前目录不会自动包含在类路径中(与不使用这些标志相反)

答案 1 :(得分:0)

NoClassDefFoundError意味着该文件在编译期间存在但在运行时无法找到,因为类路径未正确设置。检查这个的一种方法是在winzip中打开你的.jar文件,它会显示jar中存在的所有文件。当你遇到这个异常时,你会发现你的班级中缺少你的班级