Idea中连接HugeGraph服务器出现NoSuchFieldError: EXCLUDE_EMPTY
1、发生错误场景(开发环境)
import java.io.IOException; import java.util.Iterator; import java.util.List; import java.util.Map; import com.baidu.hugegraph.driver.GremlinManager; import com.baidu.hugegraph.driver.HugeClient; import com.baidu.hugegraph.driver.SchemaManager; public class SingleExample { public static void main(String[] args) throws IOException { HugeClient hugeClient = null; try { // If connect failed will throw a exception. hugeClient = HugeClient.builder("http://192.168.66.83:8080", "hugegraph") .build(); SchemaManager schema = hugeClient.schema(); schema.propertyKey("aaa3").asText().valueSingle().ifNotExist().create(); }catch (Exception e){ e.printStackTrace(); }finally { hugeClient.close(); } } }
Maven依赖如下:
<dependency> <groupId>com.baidu.hugegraph</groupId> <artifactId>hugegraph-client</artifactId> <version>1.9.0</version> </dependency>
2、发生错误时的报错内容
Exception in thread "main" java.lang.NoSuchFieldError: EXCLUDE_EMPTY at org.glassfish.jersey.client.ClientConfig$State.<init>(ClientConfig.java:150) at org.glassfish.jersey.client.ClientConfig.<init>(ClientConfig.java:468) at com.baidu.hugegraph.rest.AbstractRestClient$ConfigBuilder.<init>(AbstractRestClient.java:419) at com.baidu.hugegraph.rest.AbstractRestClient.<init>(AbstractRestClient.java:117) at com.baidu.hugegraph.client.RestClient.<init>(RestClient.java:55) at com.baidu.hugegraph.driver.HugeClient.<init>(HugeClient.java:59) at com.baidu.hugegraph.driver.HugeClientBuilder.build(HugeClientBuilder.java:70)
3、解决思路
看上去像是版本问题,百度也找不出答案,最后把Maven依赖调换的一下顺序就好了,我这个老工程依赖比较多,我添加hugegraph-client依赖的时候习惯性的把它放到pom文件的末尾,所以运行程序就报错了。
因此将依赖放置pom文件的最前面即可。