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...

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-data-elasticsearch</artifactId>
</dependency>
<dependency>
	<groupId>org.elasticsearch.client</groupId>
	<artifactId>elasticsearch-rest-client</artifactId>
</dependency>

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 org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.findConstructorBindingAnnotatedConstructor(ConfigurationPropertiesBindConstructorProvider.java:62)
>         at org.springframework.boot.context.properties.ConfigurationPropertiesBindConstructorProvider.getBindConstructor(ConfigurationPropertiesBindConstructorProvider.java:48)
>         at org.springframework.boot.context.properties.ConfigurationPropertiesBean$BindMethod.forType(ConfigurationPropertiesBean.java:311)
>         at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.validate(ConfigurationPropertiesBeanDefinitionValidator.java:63)
>         at org.springframework.boot.context.properties.ConfigurationPropertiesBeanDefinitionValidator.postProcessBeanFactory(ConfigurationPropertiesBeanDefinitionValidator.java:45)
>         at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:286)
>         at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:174)
>         at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:706)
>         at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
>         at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141)
>         at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747)
>         at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
>         at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
>         at com.m2g.superlog.SuperlogApiApplication.main(SuperlogApiApplication.java:18)
>         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 org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
>         at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
>         at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)
>         at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
> Caused by: java.lang.ClassNotFoundException: org.elasticsearch.action.Action
>         at java.net.URLClassLoader.findClass(Unknown Source)
>         at java.lang.ClassLoader.loadClass(Unknown Source)
>         at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:92)
>         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:

<properties>
  <elasticsearch.version>7.5.2<elasticsearch.version>
</properties>

See documentation here: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-build.html#howto-customize-dependency-versions

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.