Mehran
Mehran

Reputation: 16831

Why I'm getting ClassNotFoundException while the package is listed as dependency in the pom.xml

I've just asked another question since I was facing some ClassNotFoundException.

Caused by: java.lang.ClassNotFoundException: org.elasticsearch.plugins.NetworkPlugin
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_131]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_131]
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) ~[na:1.8.0_131]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_131]
    ... 56 common frames omitted

It's been pointed out to me that this exception means that the mentioned class is not found in the classpath at runtime. This is in the case that I have the container package in the pom.xml file.

<dependency>
    <groupId>org.elasticsearch</groupId>
    <artifactId>elasticsearch</artifactId>
    <version>5.5.0</version>
</dependency>

So now my question is, how can a package be named as a dependency but some class in it be missing at runtime? And also, mvn dependency:tree -Dverbose -Dincludes=commons-collections returns no conflict.

This is a Spring Boot project that I'm running using IntelliJ Idea in debug mode. I'm also using a dozen other packages in my code in the exact same way and they all work smoothly. But as soon as I add Elasticsearch, I face the mentioned exception.

Upvotes: 1

Views: 1130

Answers (4)

JFPicard
JFPicard

Reputation: 5168

You've missed the plugin part.

<!-- https://mvnrepository.com/artifact/org.elasticsearch.plugin/plugins -->
<dependency>
    <groupId>org.elasticsearch.plugin</groupId>
    <artifactId>plugins</artifactId>
    <version>2.4.5</version>
    <type>pom</type>
</dependency>

Maybe you also need the transport part:

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>5.5.0</version>
</dependency>

See if this link helps: Elasticsearch TransportClient NetworkPlugin NoClassDefFoundError

Upvotes: 0

XPLOT1ON
XPLOT1ON

Reputation: 3223

Can you try deleting the downloaded dependency from your computer.

It is located at ~/.m2/repository/org/elasticsearch Assuming you keep maven dependencies in default location and running on a Mac OS X

rm -rf ~/.m2/repository/org/elasticsearch/*

Afterwards try re-downloading the dependency using

mvn dependency:resolve

Upvotes: 1

Ivan Lynch
Ivan Lynch

Reputation: 562

Did you try clean and build?, because sometimes when you add a dependency to your pom.xml you will see that the library is downloading but if you try to execute your project without build it you get that error.

Upvotes: 0

Anshul Sharma
Anshul Sharma

Reputation: 3522

you can try use one bellow version elasticsearch` of dependency. you can try one dependency from bellow dependencies :-

<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.4.3</version>
</dependency>

or

<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>6.0.0-alpha2</version>
</dependency>

Upvotes: 0

Related Questions