2

I know that the "Unsupported major.minor version 52.0" Error points to the fact that the java code was compiled with Java 8 and it was attempted to execute it with an earlier version.

I know that it is therefore suggested to have JAVA_HOME and PATH point to the correct version of Java.

From all that I can tell I have my system already pointing to the correct version:

me@computer ~ $ java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
me@computer ~ $ which java
/home/me/bin/jdk1.8.0_102_64bit/bin/java
me@computer ~ $ echo $JAVA_HOME
/home/me/bin/jdk1.8.0_102_64bit

However, I still get the below error when trying to execute elasticsearch (installed via apt-get):

me@computer ~ $ sudo -i service elasticsearch start
 * Starting Elasticsearch Server
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/elasticsearch/bootstrap/Elasticsearch : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
...
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

Edit:

The PATH variable (in constrast to other variables like JAVA_HOME) is reset with sudo on ubuntu-based linuxes, one suggested solution is to set the variable again using sudo env:

me@computer ~ $ sudo echo $JAVA_HOME
/home/me/bin/jdk1.8.0_102_64bit
me@computer ~ $ sudo java -version
java version "1.7.0_121"
OpenJDK Runtime Environment (IcedTea 2.6.8) (7u121-2.6.8-1ubuntu0.14.04.1)
OpenJDK 64-Bit Server VM (build 24.121-b00, mixed mode)
me@computer ~ $ sudo env PATH=$PATH java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

However, this does not work for my actual problem (starting Elasticsearch):

me@computer ~ $ sudo env PATH=$PATH service elasticsearch start
 * Starting Elasticsearch Server
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/elasticsearch/bootstrap/Elasticsearch : Unsupported major.minor version 52.0
    at java.lang.ClassLoader.defineClass1(Native Method)
...
benroth
  • 2,468
  • 3
  • 24
  • 25
  • Running sudo may pose a different java-version than you'd expect. Could you e.g print the java-version within the script and then take it from there? Might be that the script itself defines a different java-version? Or some other property? I would just do an `java -version; which java` within the script itself (`/etc/init.d/elasticsearch`) :-) – vegaasen Feb 16 '17 at 09:43
  • 2
    I am not familiar with Linux, but maybe the `sudo` command runs with another user that has another path (or Java installation)? Is it possible to run a command like `sudo java -version` to find that out? – Seelenvirtuose Feb 16 '17 at 09:45
  • updated my question - a workaround works for `sudo java -version`, but not for my actual problem. – benroth Feb 16 '17 at 12:44

1 Answers1

0

+1

having same issue on Debian Jessie

Distributor ID: Debian Description: Debian GNU/Linux 8.6 (jessie) Release: 8.6 Codename: jessie

instantlink
  • 180
  • 1
  • 9