-1

I'm trying to run Spring Boot executable-jar built using spring-boot-maven-plugin on a Linux machine. The machine has multiple jdks installed, the one on PATH is jdk8 and changing it is unfortunately not an option. My executable-jar however needs jdk17, so when I just launch it as is I get UnsupportedClassVersionError.

I was following the official documentation and created the corresponding .conf file to override JAVA_HOME. But this does not seem to solve the issue:

[root@ios-maket updater-new]# ls
updater-new-3.0-SNAPSHOT.conf  updater-new-3.0-SNAPSHOT.jar
[root@ios-maket updater-new]# cat updater-new-3.0-SNAPSHOT.conf
JAVA_HOME=/opt/jdk-17/bin/java
[root@ios-maket updater-new]# ./updater-new-3.0-SNAPSHOT.jar
Application is running as root (UID 0). This is considered insecure.
Exception in thread "main" java.lang.UnsupportedClassVersionError...

On the other hand if I run it manually everything works fine:

[root@ios-maket updater-new]# /opt/jdk-17/bin/java -jar ./updater-new-3.0-SNAPSHOT.jar
[main] INFO com.icl.ios.fias.updaternew.UpdaterNew - Starting UpdaterNew using Java 17.0.6

What am I doing wrong?

2 Answers2

0

Try running the jar with -Dloader.path to specify the config manually.

java -Dloader.path=./updater-new-3.0-SNAPSHOT.conf -jar ./updater-new-3.0-SNAPSHOT.jar

If this still does not work, then probably there is an issue with your config file, but from what I can see, your config file looks okay, unless the java path is incorrect.

Rusu Dinu
  • 477
  • 2
  • 5
  • 16
0

Setting JAVA_HOME is not enough, you also need to set PATH to point to JAVA_HOME/bin.

JAVA_HOME=/opt/jdk-17
PATH=${JAVA_HOME}/bin:$PATH
java -jar updater-new-3.0-SNAPSHOT.jar
life888888
  • 835
  • 2
  • 2
  • 8
  • Thanks, your answer pointed me in the right direction. If `JAVA_HOME` is specified in .conf file - SpringBoot init script will handle the PATH. So what I needed was to change `JAVA_HOME` to `/opt/jdk-17`. Now the app launches with command `./updater-new-3.0-SNAPSHOT.jar` – Alexey Nurmukhametov Feb 14 '23 at 09:18