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

16,329

Solution 1

In case you still have this problem... or just for curiosity... take a look at the file ./bin/elasticsearch-env.sh, around the line 70, look for the command:

"$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JavaVersionChecker

Check if it is correctly "spelled" for your environment, write this command just before it and see what you've got:

echo "$JAVA" -cp "$ES_CLASSPATH" org.elasticsearch.tools.launchers.JavaVersionChecker 

in my case... I was running in a Git Bash inside a Windows machine, and the command was pointing to:

/c/Users/Ualter/Developer/ELKStack/elasticsearch-6.2.2/lib/*

Changing to:

/Users/Ualter/Developer/ELKStack/elasticsearch-6.2.2/lib/* 

As I was running on a Windows S.O. it get up and running OK the Elasticsearch.

Solution 2

I also encounter such strange question, the first time it raises exception for running elastic as root, after I add a new user elastic and run it as elastic , I see this exception "Could not find or load main class org.elasticsearch.tools.launchers.JavaVersionChecker ".

I solved this problem by moving the program dirs to the non /root/ dirs, for example, I put it to /opt/elk/, and it works.

So I guess elastic may not allow to run as root for security , thus we can not put the program in the root user's dir. Hope it can make some tips for you.

Solution 3

I was trying hard to use elasticsearch 6.7.1 on Windows.

I had this exact error when running bin/elasticsearch.bat .

Long story short, there was probably an issue with my java version and elastic search, it couldn't run the jars (using Java 8 211).

I installed the last ElasticSearch 6.x from here :

https://www.elastic.co/downloads/past-releases#elasticsearch

And unset the existing ES_HOME and ES_CLASSPATH environment variables that I created, and all went well.

Share:
16,329
lengthy_preamble
Author by

lengthy_preamble

Updated on June 14, 2022

Comments

  • lengthy_preamble
    lengthy_preamble almost 2 years

    I'm using CentOS and have downloaded Elasticsearch 6.2.1. I created a new user "elastic" and when I run ./bin/elasticsearch I get the error:

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

    I tried placing this user in an admin group ("wheel"), and the same problem occurs. If I try it with "sudo ./bin/elasticsearch" I get:

    [2018-02-15T17:42:39,776][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:125) ~[elasticsearch-6.2.1.jar:6.2.1]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.2.1.jar:6.2.1]
    at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.2.1.jar:6.2.1]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.2.1.jar:6.2.1]
    at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.2.1.jar:6.2.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.2.1.jar:6.2.1]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.2.1.jar:6.2.1]
    Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-6.2.1.jar:6.2.1]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-6.2.1.jar:6.2.1]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.1.jar:6.2.1]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.1.jar:6.2.1]
    

    I searched a bit and saw that it this error can be due to the java version, but it seems to be up to date:

    [elastic@sandbox-hdp elasticsearch-6.1.1]$ sudo update-alternatives --config java
    
    There are 3 programs which provide 'java'.
    
    Selection Command
    1 /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
    *+ 2 /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java
    3 /usr/lib/jvm/jre-1.5.0-gcj/bin/java
    

    This also happens if I try Elasticsearch 6.1

    Any suggestions would be appreciated.

  • MJ Convento
    MJ Convento about 5 years
    I'm using elasticsearch 6.7, then changed the file "elasticsearch-env" in line 36 from: ES_CLASSPATH="$ES_HOME/lib/*" to: ES_CLASSPATH="/Users/Username/Desktop/elasticsearch-6.7.1/li‌​b/*"