5.3.2版本报 java.lang.NoClassDefFoundError: org/apache/lucene/util/SetOnce
Elasticsearch | 作者 syj | 发布于2017年05月06日 | 阅读数:15273
代码和报错,是不是lucene版本不匹配呢?
package es;
import java.net.InetAddress;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
public class esClient {
private static Logger loger = null;
public static void main(String[] args) {
try {
loger = LogManager.getLogger(esClient.class.getName());
loger.info("start..");
//设置集群名称
Settings settings1 = Settings.builder().put("cluster.name", "my-elasticsearch")
.put("client.transport.sniff", false).build();
//创建client
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.224.140"), 9300));
//搜索数据
GetResponse response = client.prepareGet("blog", "article", "1").execute().actionGet();
//输出结果
System.out.println(response.getSourceAsString());
//关闭client
client.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
start..
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/util/SetOnce
at org.elasticsearch.common.settings.Settings$Builder.<init>(Settings.java:676)
at org.elasticsearch.common.settings.Settings$Builder.<clinit>(Settings.java:671)
at org.elasticsearch.common.settings.Settings.<clinit>(Settings.java:84)
at es.esClient.main(esClient.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.SetOnce
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 4 more
maven的pom.xml
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
package es;
import java.net.InetAddress;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
public class esClient {
private static Logger loger = null;
public static void main(String[] args) {
try {
loger = LogManager.getLogger(esClient.class.getName());
loger.info("start..");
//设置集群名称
Settings settings1 = Settings.builder().put("cluster.name", "my-elasticsearch")
.put("client.transport.sniff", false).build();
//创建client
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.224.140"), 9300));
//搜索数据
GetResponse response = client.prepareGet("blog", "article", "1").execute().actionGet();
//输出结果
System.out.println(response.getSourceAsString());
//关闭client
client.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
start..
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/util/SetOnce
at org.elasticsearch.common.settings.Settings$Builder.<init>(Settings.java:676)
at org.elasticsearch.common.settings.Settings$Builder.<clinit>(Settings.java:671)
at org.elasticsearch.common.settings.Settings.<clinit>(Settings.java:84)
at es.esClient.main(esClient.java:20)
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.util.SetOnce
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 4 more
maven的pom.xml
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
5 个回复
qsfjing
赞同来自:
yayg2008
赞同来自:
wuyh
赞同来自:
我被这个破玩意儿困扰了一天了
Tommy Yang
赞同来自:
vidi - vidi, or I see, but not con conquer, just a pass-by.
赞同来自: