Action class not found on jar file, but works on Eclipse, how is that?

I am using Spring Boot Starter to persist data to Elasticsearch but when I build the jar file it says there is a missing class.

What´s wrong? I am using 7.5.2 version.

My pom.xml dependency is...


Console error when I try:

% java -jar javapp.jar

> 03/02/2020 15:55:28.890 -> No active profile set, falling back to default profiles: default
> 03/02/2020 15:55:29.582 -> Bootstrapping Spring Data Elasticsearch repositories in DEFAULT mode.
> 03/02/2020 15:55:29.591 -> Finished Spring Data repository scanning in 5ms. Found 0 Elasticsearch repository interfaces.
> 03/02/2020 15:55:29.854 -> Bootstrapping Spring Data Elasticsearch repositories in DEFAULT mode.
> 03/02/2020 15:55:29.900 -> Finished Spring Data repository scanning in 46ms. Found 1 Elasticsearch repository interfaces.
> 03/02/2020 15:55:29.905 -> Bootstrapping Spring Data Reactive Elasticsearch repositories in DEFAULT mode.
> 03/02/2020 15:55:29.909 -> Finished Spring Data repository scanning in 3ms. Found 0 Reactive Elasticsearch repository interfaces.
> 03/02/2020 15:55:30.125 -> Application run failed
> java.lang.NoClassDefFoundError: org/elasticsearch/action/Action
>         at java.lang.Class.getDeclaredConstructors0(Native Method)
>         at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
>         at java.lang.Class.getDeclaredConstructors(Unknown Source)
>         at
>         at
>         at$BindMethod.forType(
>         at
>         at
>         at
>         at
>         at
>         at
>         at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(
>         at org.springframework.boot.SpringApplication.refresh(
>         at org.springframework.boot.SpringApplication.refreshContext(
>         at
>         at
>         at
>         at com.m2g.superlog.SuperlogApiApplication.main(
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>         at java.lang.reflect.Method.invoke(Unknown Source)
>         at
>         at org.springframework.boot.loader.Launcher.launch(
>         at org.springframework.boot.loader.Launcher.launch(
>         at org.springframework.boot.loader.JarLauncher.main(
> Caused by: java.lang.ClassNotFoundException: org.elasticsearch.action.Action
>         at Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(
>         at java.lang.ClassLoader.loadClass(Unknown Source)

Actually looking inside Maven Dependencies jars I can't find that class, but the strange is when I run on Eclipse everything works.

When using springboot with
elasticsearch, you need to be explicit with some transitive dependencies as SpringBoot declares a version 6.4...

Basically you can put this in your pom.xml:


See documentation here:

Thanks a lot.

Actually I removed the version number from properties and Spring used version 6.8.6, problem solved.

In my mind that doesn't make sense because it should be pointing to the newest version since the Elasticsearch is 7.5.2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.