Riak Java Client无法编译

时间:2012-12-26 01:32:21

标签: java riak

我正在和riak一起工作。试图从Java访问它。这是代码:

package eee.xxx;

import com.basho.riak.client.IRiakClient;
import com.basho.riak.client.RiakException;
import com.basho.riak.client.RiakFactory;
import com.basho.riak.client.bucket.Bucket;

public class Main {

    /**
     * @param args
     * @throws RiakException 
     */
    public static void main(String[] args) throws RiakException {
        IRiakClient myClient = RiakFactory.httpClient("127.0.0.1");
        Bucket myBucket = myClient.fetchBucket("Pacan").execute(); 
    }

}

在编译之后,它会抛出这样的错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException
    at com.basho.riak.client.raw.http.HTTPClientAdapter.<init>(HTTPClientAdapter.java:85)
    at com.basho.riak.client.RiakFactory.httpClient(RiakFactory.java:144)
    at eee.xxx.Main.main(Main.java:18)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 3 more

我不知道如何解决这个问题。请帮忙! : - )

1 个答案:

答案 0 :(得分:1)

Riak有3个 rd 派对库依赖项,其中一个是您似乎缺少的标准JSON库。它需要在编译和放大的类路径上可用。运行。它可以找到here

由于存在大约8个依赖项,因此通过添加依赖项让Maven为您管理此更容易:

<dependency>
    <groupId>com.basho.riak</groupId>
    <artifactId>riak-client</artifactId>
    <version>1.0.6</version>
</dependency>