启动 Elasticsearch 时出现异常。
java.lang.NoClassDefFoundError: org/xerial/snappy/Snappy
at org.elasticsearch.common.compress.snappy.xerial.XerialSnappy.<clinit>(XerialSnappy.java:42) ~[elasticsearch-0.20.6.jar:na]
at org.elasticsearch.common.compress.CompressorFactory.<clinit>(CompressorFactory.java:58) ~[elasticsearch-0.20.6.jar:na]
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:161) [elasticsearch-0.20.6.jar:na]
at org.elasticsearch.client.transport.TransportClient.<init>(TransportClient.java:109) [elasticsearch-0.20.6.jar:na]
at no.breakpoint.service.search.SearchClientFactory.getClient(SearchClientFactory.java:17) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0]
at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0]
//....
Caused by: java.lang.ClassNotFoundException: org.xerial.snappy.Snappy
at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[na:1.7.0]
at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0]
at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[na:1.7.0]
at java.lang.ClassLoader.loadClass(ClassLoader.java:423) ~[na:1.7.0]
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) ~[na:1.7.0]
at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ~[na:1.7.0]
POM 中的依赖:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>0.20.6</version>
</dependency>
如果我在 POM 中添加这个依赖项,异常就会消失。但是,这是什么原因(或者,我知道这通常意味着在类路径中找不到该库并添加依赖项可以修复它,但是 Elasticsearch 的传递依赖项是否有问题)?
<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>1.0.4.1</version>
</dependency>