Selenium Java error on Linux - lmmx/devnotes GitHub Wiki

Trying to set up RSelenium, after running rsDriver() and allowing it to install [3 versions of] Selenium,

find / -iname "selenium-server-standalone-*" 2> /dev/null
/home/louis/.local/share/binman_seleniumserver/generic/3.3.1/selenium-server-standalone-3.3.1.jar
/home/louis/.local/share/binman_seleniumserver/generic/3.4.0/selenium-server-standalone-3.4.0.jar
/home/louis/.local/share/binman_seleniumserver/generic/3.3.0/selenium-server-standalone-3.3.0.jar

rsDriver() reports what appears to be an incompatibility with my default Java, reproduced directly via:

java -jar /home/louis/.local/share/binman_seleniumserver/generic/3.4.0/selenium-server-standalone-3.4.0.jar
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/openqa/grid/selenium/GridLauncherV3 : Unsupported major.minor version 52.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

According to StackOverflow this "52.0" corresponds to:

  • J2SE 9 = 53
  • J2SE 8 = 52
  • J2SE 7 = 51
  • J2SE 6.0 = 50
  • J2SE 5.0 = 49
  • JDK 1.4 = 48
  • JDK 1.3 = 47
  • JDK 1.2 = 46
  • JDK 1.1 = 45

Thus, the 'major.minor version 52.0' error is possibly because the jar was compiled in jdk 1.8, but you are trying to run it using a jdk 1.7 environment. The reported number is the required number, not the number you are using. To solve this, it's always better to have the jdk and jre pointed to the same version.

Running find / -iname "jre*" 2> /dev/null I can see that I have:

/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre
/usr/lib/jvm/java-7-openjdk-amd64/jre
/usr/lib/jvm/java-6-openjdk-amd64/jre
/usr/share/jetty/jre1.5
/usr/share/jetty/lib/jre1.5

to choose from, while my default Java is:

ls -l `which java`
lrwxrwxrwx 1 root root 22 Apr  6  2014 /usr/bin/java -> /etc/alternatives/java
ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 46 Apr  6  2014 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

So in short I need to update my JRE to 8.0 to match the jar compiled in JDK 1.8

Below are the commands adapted from this installation guide for Linux Mint (which missed out a sudo here and there and only removed OpenJDK v6)

  • NB JRE filename here is jre-8u144-linux-x64.tar.gz, current at time of writing, adapt as suitable
sudo apt-get update && sudo apt-get remove openjdk-6-jre && sudo apt-get remove openjdk-7-jre
sudo apt-get autoremove && sudo apt-get clean
cd ~/Downloads
tar -zxvf jre-8u144-linux-x64.tar.gz
sudo mv -v jre1.8.0_* /opt/java/64
sudo update-alternatives --install "/usr/bin/java" "java" "/opt/java/64/jre1.8.0_144/bin/java" 1
sudo update-alternatives --set java /opt/java/64/jre1.8.0_144/bin/java

java -version will now show the updated version

There's also an extra bit to run if you're a Firefox user:

mkdir -v ~/.mozilla/plugins
ln -s /opt/java/64/jre1.8.0_144/lib/amd64/libnpjp2.so ~/.mozilla/plugins/