Q:非洲食人族的酋长吃什么?

5.3.2版本报 java.lang.NoClassDefFoundError: org/apache/lucene/util/SetOnce

Elasticsearch | 作者 syj | 发布于2017年05月06日 | 阅读数:15344

代码和报错,是不是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>
已邀请:

qsfjing

赞同来自:

您好请问这个问题有解决嘛 现在也遇到了相同的问题还没有找到好的解决办法 谢谢

yayg2008

赞同来自:

检查一下你的项目中是否有多个lucene-core包,导致版本冲突。

wuyh

赞同来自:

哥们儿,你怎么解决的啊??
我被这个破玩意儿困扰了一天了

Tommy Yang

赞同来自:

想问下这个问题后面是怎么解决的, 解决了嘛?

vidi - vidi, or I see, but not con conquer, just a pass-by.

赞同来自:

`mvn dependency:tree` 打印依赖信息检查依赖项,如果是用的IDE请检查classpath中是否添加了多个版本的的lucene包,NoClassDefFound一般是同一个包的多次饮用造成的,检查一下依赖的配置就好。

要回复问题请先登录注册