Error: Could not find or load main class org.elasticsearch.tools.JavaVersionChecker

i tried to install elasticsearch 5.3 inside my docker, after adding a new user elsearch with following commands:
groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
chown -R elsearch:elsearch /root/elasticsearch-5.3.0/
su elsearch
cd /root/elasticsearch-5.3.0/bin/

and i tried to run elasticsearch:
./elasticsearch

i get error:
Error: Could not find or load main class org.elasticsearch.tools.JavaVersionChecker
Elasticsearch requires at least Java 8 but your Java version from /usr/bin/java does not meet this requirement

and i run java -version:
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

the system of docker is ubuntu 14.04
uname -a
Linux ced2897c0f3f 4.8.0-46-generic #49~16.04.1-Ubuntu SMP Fri Mar 31 14:51:03 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

free -m
total used free shared buffers cached
Mem: 7886 5457 2428 456 467 1852
-/+ buffers/cache: 3138 4747
Swap: 8093 0 8093

what's wrong... somebody help?

Hi,

I am not sure how your running Elasticsearch "inside your docker" is the right way. You should build a separate container. Refer to our documentation here:

https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html

From your docker container I would check:

sudo update-alternatives --config java

And see where /usr/bin/java points to. You may need to fix where /usr/bin/java points to, if it doesn't point to the same java version.

It's not clear to me how you've built your Docker image but all Elasticsearch distributions since 5.3.0 ship with a jar that contains org.elasticsearch.tools.JavaVersionChecker but it's clear that somehow you've lost that jar file. This is the root of your problem. Without more details, we can not help.

Same Jar file is working in MAC. but it is not working in Centos 7.
alternatives --config java

There are 3 programs which provide 'java'.

Selection Command

  • 1 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64/jre/bin/java)
    2 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86_64/jre/bin/java)
  • 3 /usr/java/jdk1.8.0_73/jre/bin/java

Enter to keep the current selection[+], or type selection number: 1

I Try to install zip (5.3.2) file in centos 7 machine:
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-514.el7.x86_64
Architecture: x86-64
I changed to openjdk version "1.8.0_102"
OpenJDK Runtime Environment (build 1.8.0_102-b14)
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)

still i got this error: [siva@kfos-vmelk-1 bin]$ ./elasticsearch
Error: Could not find or load main class org.elasticsearch.tools.JavaVersionChecker
Elasticsearch requires at least Java 8 but your Java version from /bin/java does not meet this requirement

The problem might not appear be your Java version, the problem appears to be with your Elasticsearch installation first. Can you please list the contents of ../lib (from the directory where you were executing elasticsearch which you show as bin, go down one directory, and then into the lib directory. Please show the entire contents here.

/root/elk/5.3.2/elasticsearch-5.3.2/lib
[root@kfos-vmelk-1 lib]# ls
elasticsearch-5.3.2.jar jackson-dataformat-yaml-2.8.6.jar log4j-1.2-api-2.7.jar lucene-grouping-6.4.2.jar lucene-queryparser-6.4.2.jar securesm-1.1.jar
HdrHistogram-2.1.6.jar java-version-checker-5.3.2.jar log4j-api-2.7.jar lucene-highlighter-6.4.2.jar lucene-sandbox-6.4.2.jar snakeyaml-1.15.jar
hppc-0.7.1.jar jna-4.2.2.jar log4j-core-2.7.jar lucene-join-6.4.2.jar lucene-spatial3d-6.4.2.jar spatial4j-0.6.jar
jackson-core-2.8.6.jar joda-time-2.9.5.jar lucene-analyzers-common-6.4.2.jar lucene-memory-6.4.2.jar lucene-spatial-6.4.2.jar t-digest-3.0.jar
jackson-dataformat-cbor-2.8.6.jar jopt-simple-5.0.2.jar lucene-backward-codecs-6.4.2.jar lucene-misc-6.4.2.jar lucene-spatial-extras-6.4.2.jar
jackson-dataformat-smile-2.8.6.jar jts-1.13.jar lucene-core-6.4.2.jar lucene-queries-6.4.2.jar lucene-suggest-6.4.2.jar
[root@kfos-vmelk-1 lib]#

same issue in 5.4.0 aswell:

7-05-05T01:48:39,567][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:127) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.4.0.jar:5.4.0]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:204) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:360) ~[elasticsearch-5.4.0.jar:5.4.0]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.4.0.jar:5.4.0]
... 6 more
[root@kfos-vmelk-1 bin]# su siva
[siva@kfos-vmelk-1 bin]$ pwd
/root/elk/5.4/elasticsearch-5.4.0/bin
[siva@kfos-vmelk-1 bin]$ ./elasticsearch
Error: Could not find or load main class org.elasticsearch.tools.JavaVersionChecker
Elasticsearch requires at least Java 8 but your Java version from /bin/java does not meet this requirement

root@kfos-vmelk-1 elasticsearch-5.4.0]# cd lib/
[root@kfos-vmelk-1 lib]# ls
elasticsearch-5.4.0.jar jackson-dataformat-yaml-2.8.6.jar log4j-1.2-api-2.8.2.jar lucene-grouping-6.5.0.jar lucene-queryparser-6.5.0.jar securesm-1.1.jar
HdrHistogram-2.1.9.jar java-version-checker-5.4.0.jar log4j-api-2.8.2.jar lucene-highlighter-6.5.0.jar lucene-sandbox-6.5.0.jar snakeyaml-1.15.jar
hppc-0.7.1.jar jna-4.4.0.jar log4j-core-2.8.2.jar lucene-join-6.5.0.jar lucene-spatial3d-6.5.0.jar spatial4j-0.6.jar
jackson-core-2.8.6.jar joda-time-2.9.5.jar lucene-analyzers-common-6.5.0.jar lucene-memory-6.5.0.jar lucene-spatial-6.5.0.jar t-digest-3.0.jar
jackson-dataformat-cbor-2.8.6.jar jopt-simple-5.0.2.jar lucene-backward-codecs-6.5.0.jar lucene-misc-6.5.0.jar lucene-spatial-extras-6.5.0.jar
jackson-dataformat-smile-2.8.6.jar jts-1.13.jar lucene-core-6.5.0.jar lucene-queries-6.5.0.jar lucene-suggest-6.5.0.jar

Okay, the jar that we are looking for is there in both cases. Would you please run bash -x ./elasticsearch from the bin folder and share the results of the output here?

bash -x ./elasticsearch

  • ES_JAVA_OPTS=-Des.insecure.allow.root=true
  • echo distribution
  • grep project.name
  • test -n ''
  • test -n ''
  • test -n ''
  • test -n ''
  • test -n ''
  • test -n ''
  • test -n ''
  • test -n ''
  • CDPATH=
  • SCRIPT=./elasticsearch
  • '[' -h ./elasticsearch ']'
    ++ dirname ./elasticsearch
  • ES_HOME=./..
    ++ cd ./..
    ++ pwd
  • ES_HOME=/root/elk/5.3.2/elasticsearch-5.3.2
  • '[' -z '' ']'
  • for jvm_options in '"$ES_HOME"/config/jvm.options' /etc/elasticsearch/jvm.options
  • '[' -r /root/elk/5.3.2/elasticsearch-5.3.2/config/jvm.options ']'
  • for jvm_options in '"$ES_HOME"/config/jvm.options' /etc/elasticsearch/jvm.options
  • '[' -r /etc/elasticsearch/jvm.options ']'
    ++ parse_jvm_options ''
    ++ '[' -f '' ']'
  • ES_JAVA_OPTS=' -Des.insecure.allow.root=true'
  • '[' x = x ']'
    ++ dirname ./elasticsearch
  • for include in /usr/share/elasticsearch/elasticsearch.in.sh /usr/local/share/elasticsearch/elasticsearch.in.sh /opt/elasticsearch/elasticsearch.in.sh '~/.elasticsearch.in.sh' '"$ES_HOME/bin/elasticsearch.in.sh"' '"dirname "$0""/elasticsearch.in.sh'
  • '[' -r /usr/share/elasticsearch/elasticsearch.in.sh ']'
  • for include in /usr/share/elasticsearch/elasticsearch.in.sh /usr/local/share/elasticsearch/elasticsearch.in.sh /opt/elasticsearch/elasticsearch.in.sh '~/.elasticsearch.in.sh' '"$ES_HOME/bin/elasticsearch.in.sh"' '"dirname "$0""/elasticsearch.in.sh'
  • '[' -r /usr/local/share/elasticsearch/elasticsearch.in.sh ']'
  • for include in /usr/share/elasticsearch/elasticsearch.in.sh /usr/local/share/elasticsearch/elasticsearch.in.sh /opt/elasticsearch/elasticsearch.in.sh '~/.elasticsearch.in.sh' '"$ES_HOME/bin/elasticsearch.in.sh"' '"dirname "$0""/elasticsearch.in.sh'
  • '[' -r /opt/elasticsearch/elasticsearch.in.sh ']'
  • for include in /usr/share/elasticsearch/elasticsearch.in.sh /usr/local/share/elasticsearch/elasticsearch.in.sh /opt/elasticsearch/elasticsearch.in.sh '~/.elasticsearch.in.sh' '"$ES_HOME/bin/elasticsearch.in.sh"' '"dirname "$0""/elasticsearch.in.sh'
  • '[' -r /home/siva/.elasticsearch.in.sh ']'
  • for include in /usr/share/elasticsearch/elasticsearch.in.sh /usr/local/share/elasticsearch/elasticsearch.in.sh /opt/elasticsearch/elasticsearch.in.sh '~/.elasticsearch.in.sh' '"$ES_HOME/bin/elasticsearch.in.sh"' '"dirname "$0""/elasticsearch.in.sh'
  • '[' -r /root/elk/5.3.2/elasticsearch-5.3.2/bin/elasticsearch.in.sh ']'
  • for include in /usr/share/elasticsearch/elasticsearch.in.sh /usr/local/share/elasticsearch/elasticsearch.in.sh /opt/elasticsearch/elasticsearch.in.sh '~/.elasticsearch.in.sh' '"$ES_HOME/bin/elasticsearch.in.sh"' '"dirname "$0""/elasticsearch.in.sh'
  • '[' -r ./elasticsearch.in.sh ']'
  • . ./elasticsearch.in.sh
    ++ '[' x '!=' x ']'
    ++ ES_CLASSPATH='/root/elk/5.3.2/elasticsearch-5.3.2/lib/elasticsearch-5.3.2.jar:/root/elk/5.3.2/elasticsearch-5.3.2/lib/*'
  • break
  • '[' -x /bin/java ']'
  • JAVA=/bin/java
  • '[' '!' -x /bin/java ']'
  • '[' -z '/root/elk/5.3.2/elasticsearch-5.3.2/lib/elasticsearch-5.3.2.jar:/root/elk/5.3.2/elasticsearch-5.3.2/lib/*' ']'
  • '[' x '!=' x ']'
  • '[' x '!=' x ']'
  • /bin/java -cp '/root/elk/5.3.2/elasticsearch-5.3.2/lib/elasticsearch-5.3.2.jar:/root/elk/5.3.2/elasticsearch-5.3.2/lib/*' org.elasticsearch.tools.JavaVersionChecker
    Error: Could not find or load main class org.elasticsearch.tools.JavaVersionChecker
  • '[' 1 -ne 0 ']'
  • echo 'Elasticsearch requires at least Java 8 but your Java version from /bin/java does not meet this requirement'
    Elasticsearch requires at least Java 8 but your Java version from /bin/java does not meet this requirement
  • exit 1

Okay, what does readlink -f /bin/java and /bin/java -version show?

[siva@kfos-vmelk-1 bin]$ readlink -f /bin/java
/usr/java/jdk1.8.0_73/jre/bin/java
[siva@kfos-vmelk-1 bin]$ /bin/java -version
java version "1.8.0_73"
Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)

I noticed this, this is in /root/; are you sure that you have the right permissions? I can reproduce your issue if I do this:

22:13:58 [jason@totoro:~/elasticsearch/elasticsearch-5.3.2/bin] $ chmod 000 ../lib
22:14:22 [jason@totoro:~/elasticsearch/elasticsearch-5.3.2/bin] $ ./elasticsearch
Error: Could not find or load main class org.elasticsearch.tools.JavaVersionChecker
Elasticsearch requires at least Java 8 but your Java version from /usr/java/latest/bin/java does not meet this requirement

You can not run Elasticsearch as root anyway, so let's get it out of the root folder and make sure you have the right permissions. I think the best way to make sure that you have the right permissions is to untar the tar archive again somewhere else.

:boom:

1 Like

Thanks jasontedor. Its Working for me inside the VM...
but not able to access from the other system? do i need to change any IP Configurations?

You're welcome! You probably do, but for that we would need more details. Would you mind opening a new topic with more details of the problem and someone will take a look?

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