【问题标题】:Elastic Search java.lang.NoClassDefFoundError: org/elasticsearch/transport/Netty3Plugin弹性搜索 java.lang.NoClassDefFoundError: org/elasticsearch/transport/Netty3Plugin
【发布时间】:2017-01-25 05:38:40
【问题描述】:

我正在尝试通过使用其 java api 制作一个基本程序来熟悉 elasticsearch。我已经研究了一段时间的答案,但我不确定我执行的解决方案是否不正确,或者只是没有看到真正的问题。

我正在使用 elasticsearch-5.1.1 并下载了最新的传输版本 (5.1.1)。我还在我的项目结构中添加了这两个(包括弹性搜索下载附带的所有 jar 文件)。

提前致谢!

运行我的测试文件时,我收到以下错误。

错误:

java.lang.NoClassDefFoundError: org/elasticsearch/transport/Netty3Plugin

at org.elasticsearch.transport.client.PreBuiltTransportClient.<clinit>(PreBuiltTransportClient.java:54)
at DictionarySearch.ElasticSearch.<init>(ElasticSearch.java:41)
at test.TestIndexSearcher.verifyElasticSearch(TestIndexSearcher.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.transport.Netty3Plugin
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 30 more

我在我的 pom.xml 文件中添加了以下依赖项,并按照给定的directions 安装了 xpack。我的 pom.xml 与我的 log4j2.xml 文件一起位于 src/lib 中。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.1.1</version>
<repositories>
    <repository>
        <id>elasticsearch-releases</id>
        <url>https://maven.elasticsearch.org/releases</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.elasticsearch.client</groupId>
        <artifactId>x-pack-transport</artifactId>
        <version>5.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch-transport-wares</artifactId>
        <version>2.7.0</version>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>5.1.1</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>transport-netty3-client</artifactId>
        <version>5.1.1</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.7</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.7</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>transport-netty4-client</artifactId>
        <version>5.1.1</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>reindex-client</artifactId>
        <version>5.1.1</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>lang-mustache-client</artifactId>
        <version>5.1.1</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.elasticsearch.plugin</groupId>
        <artifactId>percolator-client</artifactId>
        <version>5.1.1</version>
        <scope>compile</scope>
    </dependency>
</dependencies>
<inceptionYear>2009</inceptionYear>
<licenses>
    <license>
        <name>The Apache Software License, Version 2.0</name>
        <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
        <distribution>repo</distribution>
    </license>
</licenses>
<developers>
    <developer>
        <name>Elastic</name>
        <url>http://www.elastic.co</url>
    </developer>
</developers>
<name>transport</name>
<description>Elasticsearch subproject :client:transport</description>
<url>https://github.com/elastic/elasticsearch</url>
<scm>
    <url>git@github.com:elastic/elasticsearch.git</url>
</scm>

【问题讨论】:

    标签: java maven elasticsearch


    【解决方案1】:

    原来我没有在我的 IDE 中正确设置 Maven。我正在使用 IntelliJ。在 IntelliJ 中,您必须在设置项目时指明您使用的是 maven。

    为了解决我的问题,我在 maven 中创建了一个新项目并将我的 java 类文件移过来。为我自动创建了一个 pom.xml 文件。我能够只将我需要的依赖项添加到 pom.xml 文件中,并使用 Maven 自动将它们导入到我的项目中。

    如果您遇到此问题,我建议您仔细检查您的 IDE 是否按照您认为的方式使用 Maven。

    【讨论】:

      猜你喜欢
      • 2018-02-15
      • 2020-08-21
      • 1970-01-01
      • 2014-08-04
      • 2018-07-05
      • 2021-11-23
      • 1970-01-01
      • 2018-10-26
      • 1970-01-01
      相关资源
      最近更新 更多