2

I installed java 11.0.7-open using sdkman and I get this error:

bash: /home/pi/.sdkman/candidates/java/11.0.7-open/bin/java: cannot execute binary file: Exec format error

when running java --version or java -jar some_file.jar (specifically 'SKlauncher 3-beta.15.jar').

Why do I get this error and how to make java work?

Cimlah
  • 55
  • 9
  • What is the output of the command file /home/pi/.sdkman/candidates/java/11.0.7-open/bin/java ? – Ephemeral May 12 '20 at 11:27
  • @Ephemeral if you mean the content inside the file, then it's encoded – Cimlah May 12 '20 at 11:36
  • No the result of the command file /home/pi/.sdkman/candidates/java/11.0.7-open/bin/java – Ephemeral May 12 '20 at 11:37
  • .sdkman/candidates/java/current/bin/java: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.18, BuildID[sha1]=092cfbfe7cf2936bdbc489b4ec39bebcff2b0b12, not stripped – Cimlah May 12 '20 at 11:40
  • And what is your arch, 32 or 64-bit ? – Ephemeral May 12 '20 at 11:48
  • @Ephemeral I think it's 64-bit. I use Raspberry Pi 4B, so it's probably 64-bit – Cimlah May 12 '20 at 11:48
  • What is the output of uname -m ? – Ephemeral May 12 '20 at 11:51
  • @Ephemeral armv7l – Cimlah May 12 '20 at 11:52
  • I think it's a 32-bit version... try to install 32-bit executable file. – Ephemeral May 12 '20 at 11:53
  • @Ephemeral Yes, it's 32-bit. Just checked on Internet – Cimlah May 12 '20 at 11:54
  • So... Can I install Java for 32-bit using sdkman? – Cimlah May 12 '20 at 11:55
  • Sorry I do not know. – Ephemeral May 12 '20 at 11:58
  • 3
    Doesn't look that it's about 32 or 64 bit. That executable is for x86 (Intel) processors, not for ARM. – Dirk May 12 '20 at 12:38
  • As Dirk points out the problem isn't just the bus width/address size (32 or 64 bits). It's the ISA. Pi's, like most smartphones, are ARM based. But you indicate an x86-64 binary; the 32-bit version of that is just plain x86, but it will still not work because it is an Intel/AMD ISA, like most laptops/desktops etc. This is probably sdkman's fault -- either it is misconfigured or very poorly designed, I'm inclined toward the former. There is no point in it if it cannot install the correct version for the platform. – goldilocks May 12 '20 at 13:25
  • @Dirk You should write an answer. – Ingo May 13 '20 at 11:11

1 Answers1

2

Not only 32-bit versus 64-bit is important, but also that the JDK is compiled for the ARM-processor. For that reason I prefer to use BellSoft LibericaJDK which has a Raspberry Pi-version and also includes JavaFX in case you want to run a JavaFX UI-application.

E.g. to use JDK 13 on Raspbian OS:

$ cd /home/pi
$ wget https://download.bell-sw.com/java/13/bellsoft-jdk13-linux-arm32-vfp-hflt.deb
$ sudo apt-get install ./bellsoft-jdk13-linux-arm32-vfp-hflt.deb
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config java

When this is done, we can check the version again and it should look like this:

$ java --version
openjdk version "13-BellSoft" 2019-09-17
OpenJDK Runtime Environment (build 13-BellSoft+33)
OpenJDK Server VM (build 13-BellSoft+33, mixed mode)

More info on https://webtechie.be/post/2020-04-08-installing-java-and-javafx-on-raspberry-pi/

Frank
  • 318
  • 1
  • 8