0

I've compiled code by: export JAVA_HOME=/usr/lib/jvm/java-8-oracle; mvn package. I have:

Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.8.0_101, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: cs_CZ, platform encoding: UTF-8
OS name: "linux", version: "3.16.0-77-generic", arch: "amd64", family: "unix"

But after running by java -jar ... I'm getting an error: Unsupported major.minor version 52.0 Does anyone know what I do wrong? I've read than this error appears when compilation was in older java but running is in newer java or vice versa, but I'm using java 8 in both cases.

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Sergey Panov
  • 313
  • 1
  • 4
  • 15

1 Answers1

2

The default Java VM set for your system is different (java7 or earlier) by those used when running mvn (java8).

You could either run

/usr/lib/jvm/java-8-oracle/bin/java -jar

or set JAVA_HOME in your ~/.mavenrc

JAVA_HOME=/usr/lib/jvm/java-8-oracle

If you're running Ubuntu, to fix it "forever" you should run this command as root:

sudo update-alternatives --config java

that will show java alternatives installed on your system, and you'll be able to set which one should be the default one (java8 in your case).

You may want to do the same for other java commands, such as:

sudo update-alternatives --config javac
sudo update-alternatives --config java_vm
sudo update-alternatives --config jcontrol
sudo update-alternatives --config jexec
David
  • 2,987
  • 1
  • 29
  • 35
  • Unfortunately it doesn't solve the problem ... $ export JAVA_HOME=/usr/lib/jvm/java-8-oracle; java -jar target/corpproc-1.0-SNAPSHOT-jar-with-dependencies.jar -c src/main/resources/config.yaml index /mnt/data/indexes/wikipedia/xpanov00/final2/ /mnt/data/indexes/wikipedia/xpanov00/final2/final/ Exception in thread "main" java.lang.UnsupportedClassVersionError: cz/vutbr/fit/knot/corpproc/cli/Cli : Unsupported major.minor version 52.0 – Sergey Panov Oct 01 '16 at 10:31
  • what is the output of `which java`? – David Oct 01 '16 at 10:33
  • Yes: bin COPYRIGHT db include javafx-src.zip jre lib LICENSE man README.html release src.zip THIRDPARTYLICENSEREADME-JAVAFX.txt THIRDPARTYLICENSEREADME.txt – Sergey Panov Oct 01 '16 at 10:37
  • `xpanov00@athena2:~$ which java /usr/bin/java ` – Sergey Panov Oct 01 '16 at 10:38
  • I updated my answer, also giving some instruction to configure Ubuntu. Let me know if you're using a different OS. – David Oct 01 '16 at 10:45
  • Thank you, it works, but I still don't understand why `export JAVA_HOME...` didn't solve this problem. – Sergey Panov Oct 01 '16 at 10:45
  • 1
    "export JAVA_HOME" is completely irrelevant when you start the `java` program directly. `JAVA_HOME` is only used in some scripts that try to find a java install. Typing `java` directly uses whatever the shell finds in your `PATH`. – zapl Oct 01 '16 at 11:09
  • setting JAVA_HOME on command line is useful if you're running a script that uses it such as `JAVA_HOME/bin/java -jar ...`. As you're running java directly and without such script, JAVA_HOME is not used. – David Oct 01 '16 at 16:37