RocksDb在IDEA中的安装与调试

时间:2024-04-07 21:07:33

经历各种坑,终于能在IDEA中成功安装调试RocksDB了,现总结如下:

1、下载

(1)在官网下载 rocksdb-rocksdb-4.1.zip 并解 压;

(2)在org.kevoree.mwg下载rocksdb-6.jar,网址:https://www.mvnjar.com/org.kevoree.mwg.plugins/rocksdb/6/detail.html(或下载最新版https://www.mvnjar.com/org.kevoree.mwg.plugins/rocksdb/jar.html)。

2、设置MAVEN依赖

<dependency>
    <groupId>org.kevoree.mwg.plugins</groupId>
    <artifactId>rocksdb</artifactId>
    <version>6</version>
</dependency>

<dependency>
    <groupId>org.rocksdb</groupId>
    <artifactId>rocksdbjni</artifactId>
    <version>5.17.2</version>
</dependency>

3、项目加载模块

在Project structure ->Libreries中,引入org.kevoree.mwgrocksdb-6.jar,如下图:

RocksDb在IDEA中的安装与调试

4、数据库初始化并打开

 

RocksDB.loadLibrary();

RocksDB.open('db文件夹')

5、实例 

import org.rocksdb.*;
import org.rocksdb.util.SizeUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;



public class RocksdbSample {
    static {
        RocksDB.loadLibrary();
    }
    public static <db> void main(final String[] args) {

        final String db_path = System.getProperty("user.dir")+"\\dbfile";
        final String db_path_not_found = db_path + "_not_found";

        RocksDB db = null;

        try (
             final Options options = new Options();
             final Filter bloomFilter = new BloomFilter(10);
             final ReadOptions readOptions = new ReadOptions()
                     .setFillCache(false);
             final Statistics stats = new Statistics();
             final RateLimiter rateLimiter = new RateLimiter(10000000,10000, 10)) {
                try {
                    db = RocksDB.open( db_path);
                    assert (false);
                    db.put("hello".getBytes(), "world".getBytes());
                    final byte[] value = db.get("hello".getBytes());
                    assert ("world".equals(new String(value)));
                    final String str1 = db.getProperty("rocksdb.stats");
                    assert (str1 != null && !str1.equals(""));
               } catch (final RocksDBException e) {
                   System.out.format("Caught the expected exception -- %s\n", e);
               } 

              }

}