Jar cannot execute binary file exec format error

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 --v...

Asked
2 years, 9 months ago

Viewed
2k times

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?

asked May 12, 2020 at 11:22

Cimlah's user avatar

15

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/

answered May 20, 2020 at 9:58

Frank's user avatar

FrankFrank

3081 silver badge8 bronze badges

0

Содержание

  1. How to Fix ‘cannot execute binary file: Exec format error’ on Ubuntu
  2. Method 1: Using the arch Command
  3. Method 2: Using the file Command
  4. Решение проблемы с ошибкой «bash: не удаётся запустить бинарный файл: Ошибка формата выполняемого файла»
  5. О разрядности дистрибутивов Linux и о программ
  6. Запуск ARM файлов в Linux
  7. Заключение
  8. 🛠️ Исправление ошибки «Exec format» при запуске скриптов командой run-parts
  9. Решение ошибки «Exec format» при запуске скриптов командой run-parts
  10. How to fix Cannot execute binary file: exec format error?
  11. Check the architecture
  12. Check the file
  13. Install GCC and Gfortran
  14. Uncompress the file
  15. Check file permissions
  16. Use Dos2unix

How to Fix ‘cannot execute binary file: Exec format error’ on Ubuntu

While it shouldn’t happen when using the official apt-get repositories, if you download software off the Internet and run it then there’s a chance that you’ll see the dreaded bash: ./nameOfProgram: cannot execute binary file: Exec format error. This error, which is usually followed by bash: ./nameOfProgram.sh: Permission denied or something like it, indicates that Ubuntu wasn’t able to interface correctly with the binary you downloaded. This is because while it’s apparently a valid Linux binary, it’s designed for a different chipset than your kernel currently supports.

Most people using Ubuntu are on 32-bit or 64-bit processors based around a standard architecture that Intel released, regardless of who actually made their microchips. It’s important to remember that 64-bit processors can run in 32-bit mode, so if you’re getting this error even though you have a 64-bit processor there’s a chance you’re running a 32-bit version of Ubuntu. A few simple commands are all it takes to tell what your chip is operating as.

Method 1: Using the arch Command

If you’re not familiar with the type of microprocessor that you have installed on your machine, then you’ll first want to use the arch command from the command line. You’ll only see a single line of output returned to you after running this command. In many cases, you’ll see i686, which means that you’re on a 32-bit processor and therefore can’t run x86_64 binaries. If you instead see amd64 or something similar, then you’re on an x86_64 processor, and should at least theoretically be able to run most 32-bit and 64-bit binaries. Unlike Microsoft Windows, Ubuntu Linux actually contains the proper tools to permit users of 644-bit chipsets to run 16-bit Windows programs in their operating system in many cases as well.

These terms are still true even if you’re not actually using that particular model of microchip. For instance, i686 is how Linux refers to many 32-bit processors even if they aren’t actually Intel 80686 chips. Even if you’re using 64-bit Intel technology, arch might still call your processor an amd64 chip. This doesn’t indicate an error, and can be safely ignored. You can use cat /proc/cpuinfo or more /proc/cpuinfo to find out the exact type of processor you’re using. Since the lines in this file are long, you might want to push F11 before issuing it if you’re using a graphical terminal window. Users of a virtual console, especially those working with Ubuntu server, won’t have to worry quite as much.

You may see some other types of output, which might further restrict your options when it comes to running software. Ubuntu supported PowerPC architecture for the longest time, which is found in some workstations as well as many Classic Macintosh and older OS X Macintosh machines. You can actually still find Ubuntu repositories for these architectures, though they receive little support today. However, you more than likely won’t be able to run many Linux binaries you download from the Internet outside of the official repositories in this case. That doesn’t mean that Ubuntu doesn’t work on these machines, though you may want to look at the lighter Lubuntu distribution.

Method 2: Using the file Command

The file command identifies what different files contain, and it’s usually very accurate. Try identifying the file in question by typing file nameOfProgram to see if you get ELF 32-bit or ELF 64-bit as output. If it tells you that it’s an ELF 64-bit binary and you received i686 as output from the arch command, then there’s no way you can reasonably run it on your machine. If you’re on a 64-bit microprocessor running 32-bit Ubuntu, then you could technically reinstall the operating system, though this is a bit of an extreme step in order to run a single program.

There is also the very real possibility, however slight, that you might instead come across a binary that when you attempt to run it spews out junk characters to the terminal even if you’ve run a malware scan on it. These characters usually take the form of either lozenge-shaped blocks, or alternatively rectangular cubes that have numerical values in them. Some computer scientists call the latter tofu, and represent the Unicode values of characters that your currently installed typefaces won’t be able to display. If the terminal is displaying them like this, then you can rest assured that this is neither a font error nor anything having to do with malware. Rather, this is simply because the compiled microprocessor opcode inside of the binary is so alien to your system that it doesn’t know how to interpret some of the code.

The best way to fix this is to install the proper package for your architecture. If you’re installing packages from inside Ubuntu, then the apt-get system or the graphical Synaptic manager has you covered without any problems. If you’re downloading packages from another distribution, then you’ll need to find the right one for your architecture. Take, for example, Arch Linux’s listing of the gvim package. While the default package features the x86_64 architecture, there’s also one for the i686 chipset. This one will work on 32-bit machines that work with the Intel interrupt structure, but remember that the terms i686 and 32-bit are not mutually inclusive all the time since other chipsets Linux supports actually do feature their own 32-bit implementations.

Users exploring the whole GNU/Linux scene might come across binaries compiled for far more exotic technologies than these. Linux is truly a cross-platform code scene, so you’ll see OpenRISC, MIPS, SPARC, M32R, MN103, ARM, ARC, Alpha and many other standards binaries are compiled to work with. More than likely, you won’t be able to run any of these, though ARM is an extremely popular tablet and smartphone platform. It’s also the platform that the Raspberry Pi is based around, which means if you’re actually running Ubuntu on a mobile device or the Ubuntu MATE distribution for Raspberry Pi you’ll actually need these instead of Intel 32-bit or x86_64 binaries.

Источник

Решение проблемы с ошибкой «bash: не удаётся запустить бинарный файл: Ошибка формата выполняемого файла»

В операционной системе Linux при запуске скаченного файла, либо при запуске самостоятельно скомпилированного файла вы можете столкнуться с ошибкой:

Если у вас англоязычная локаль, то ошибка будет примерно такой:

bash: ./program: cannot execute binary file: Exec format error

В самой ошибке вместо /путь/до/файла и ./program будет указан путь до файла программы, который вы хотите запустить.

  • Причинами данной ошибки могут быть:
  • попытка запустить 64-битный файл на 32-битной системе
  • файл скомпилирован для другой архитектуры (например, для ARM, а вы пытаетесь запустить его на ПК)
  • вы пытаетесь выполнить не исполнимый файл, а ссылку
  • файл размещён в совместной (shared) папке

Чтобы получить информацию о файле, который вы пытаетесь запустить, можно использовать утилиту file, после которой укажите путь до файла:

Здесь мы видим, что файл предназначен для 64-битной системы, об этом говорит запись 64-bit, для процессора с архитектурой x86-64.

Ещё один пример:

Этот файл для 32-битных систем, для процессора с архитектурой ARM EABI4.

Если вы не знаете, какой битности ваша система, то выполните команду:

Для 64-битных систем будет выведено x86_64, а для 32-битных – x86.

О разрядности дистрибутивов Linux и о программ

На компьютер с 32-битным процессором вы можете установить только 32-битную операционную систему и в ней запускать только 32-битные программы.

На компьютер с 64-битным процессором вы можете установить как 64-битную ОС, так и 32-битный Linux. В случае, если вы установили 64-битный дистрибутив Linux, то в нём вы можете запускать и 64-битные программы и 32-битные. А если вы установили 32-битный дистрибутив, то в нём возможно запускать только 32-битные программы.

Итак, если у вас 32-битная система, а файл для 64-битной системы или даже для ARM архитектуры, то у вас следующие варианты:

  • скачать файл подходящей для вас битности и архитектуры
  • если вы самостоятельно компилировали файл из исходного кода, то заново скомпилируйте для процессора вашей архитектуры

Запуск ARM файлов в Linux

Часто можно запустить исполнимые образы ARM на amd64 системах если установить пакеты binfmt-support, qemu, и qemu-user-static:

sudo apt install binfmt-support qemu qemu-user-static

Заключение

Итак, ошибка формата выполняемого файла с невозможностью запустить бинарный файл возникает из-за несоответствия программы операционной системе или архитектуре процессора. Эта проблема не должна возникать, если вы установили программу из исходных репозиториев (кроме случаев неправильной настройки источников репозитория). При возникновении этой проблемы поищите файл, подходящий для вашей архитектуры или скомпилируйте файл из исходных кодов под архитектуру вашей операционной системы.

Источник

🛠️ Исправление ошибки «Exec format» при запуске скриптов командой run-parts

Решение ошибки «Exec format» при запуске скриптов командой run-parts

Чтобы запустить все скрипты в папке «Documents», я запустил:

Я получил следующее сообщение об ошибке:

Bourne shell, или совместимый шеллl:

Bash:

Perl:

Python 2.x:

Python 3.x:

Это то, что мы называем шебанг.

Теперь вернемся к теме.

Отредактируйте ваши скрипты, используя ваш любимый редактор:

Добавьте шебанг в начале скрипта:

Теперь вы можете без проблем запускать скрипты с помощью команды run-parts, используя команду run-parts.

Вы также можете использовать утилиту ShellCheck для поиска проблем в своих скриптах оболочки.

  • Аудит ИБ (49)
  • Вакансии (12)
  • Закрытие уязвимостей (105)
  • Книги (27)
  • Мануал (2 234)
  • Медиа (66)
  • Мероприятия (39)
  • Мошенники (23)
  • Обзоры (800)
  • Обход запретов (34)
  • Опросы (3)
  • Скрипты (109)
  • Статьи (336)
  • Философия (99)
  • Юмор (18)

Anything in here will be replaced on browsers that support the canvas element

Источник

How to fix Cannot execute binary file: exec format error?

Photo by Jivacore/Shutterstock.com

Linux has been reworked heavily since it first came out to the point that it’s no longer an OS for terminal kings. Just about everyone can use it now thanks to the much better user interfaces that we see in modern Linux distros. However, that doesn’t mean it can’t be frustrating at times.

In this article, we’re taking a look at the “cannot execute binary file: exec format error” issue and giving you a few solutions on how to get rid of the problem.

Check the architecture

The first thing you should do is ensure you’ve got the right bin file. Binary files made for 32-bit systems won’t work on 64-bit systems and vice-versa. You can check the architecture of any file by using the command below.

If the architecture doesn’t match between your file and the PC you’re running it on, try running the corresponding binary file for the matching architecture.

Check the file

Binary files can be run on Windows, Linux and macOS. However, binaries made for one OS won’t run on the others. Generally, these files have different file formats to help users distinguish between them. If you’re trying to run a binary file made for Windows on a Linux distro, it’s obviously not going to work.

If you must run the binary on Linux however, we recommend downloading Wine and using it to run the file. Wine is a compatibility layer capable of running Windows applications on POSIX-compliant operating systems, including Linux and macOS.

Install GCC and Gfortran

GCC and Gfortran are required for several binary files to compile and execute properly. You can install them by typing the command below in your terminal.

Now try running your binary file again and it should run without a problem — fixing the ‘cannot execute binary file’ error.

Uncompress the file

Sometimes binary files are compressed to make them easier to share over the internet. Try uncompressing the file to see if that helps you run it fine. Run the following commands on at a time.

Check file permissions

Another potential reason for your binary file not running could be that the user doesn’t have permission to change or read the file. You can fix this by typing the following command in the terminal.

Once the permissions are set, you can run the file by typing this.

Use Dos2unix

The Dos2unix command can sometimes help binaries made for DOS to run on UNIX systems. Try using the following command to see if your file runs or not.

If we’ve missed out on any fixes that helped you solve the ‘cannot execute binary file’ error, please comment down below with the fix.

Someone who writes/edits/shoots/hosts all things tech and when he’s not, streams himself racing virtual cars.

You can contact him here: [email protected]

Источник

Photo by Jivacore/Shutterstock.com

Linux has been reworked heavily since it first came out to the point that it’s no longer an OS for terminal kings. Just about everyone can use it now thanks to the much better user interfaces that we see in modern Linux distros. However, that doesn’t mean it can’t be frustrating at times. 

In this article, we’re taking a look at the “cannot execute binary file: exec format error” issue and giving you a few solutions on how to get rid of the problem. 

Also read: How to make a file executable in Linux?


Check the architecture

The first thing you should do is ensure you’ve got the right bin file. Binary files made for 32-bit systems won’t work on 64-bit systems and vice-versa. You can check the architecture of any file by using the command below.

file filename

How to fix Cannot execute binary file: exec format error?

If the architecture doesn’t match between your file and the PC you’re running it on, try running the corresponding binary file for the matching architecture. 


Check the file

Binary files can be run on Windows, Linux and macOS. However, binaries made for one OS won’t run on the others. Generally, these files have different file formats to help users distinguish between them. If you’re trying to run a binary file made for Windows on a Linux distro, it’s obviously not going to work. 

If you must run the binary on Linux however, we recommend downloading Wine and using it to run the file. Wine is a compatibility layer capable of running Windows applications on POSIX-compliant operating systems, including Linux and macOS. 


Install GCC and Gfortran

GCC and Gfortran are required for several binary files to compile and execute properly. You can install them by typing the command below in your terminal. 

sudo apt-get install gfortran && sudo apt-get install build-essential

How to fix Cannot execute binary file: exec format error?

Now try running your binary file again and it should run without a problem — fixing the ‘cannot execute binary file’ error.


Uncompress the file

Sometimes binary files are compressed to make them easier to share over the internet. Try uncompressing the file to see if that helps you run it fine. Run the following commands on at a time. 

xz -d ./filename
chmod +x ./filename
./filename

Check file permissions

Another potential reason for your binary file not running could be that the user doesn’t have permission to change or read the file. You can fix this by typing the following command in the terminal. 

chmod +x filename

How to fix Cannot execute binary file: exec format error?

Once the permissions are set, you can run the file by typing this.

./filename

Use Dos2unix

The Dos2unix command can sometimes help binaries made for DOS to run on UNIX systems. Try using the following command to see if your file runs or not. 

dos2unix filename.bin

If we’ve missed out on any fixes that helped you solve the ‘cannot execute binary file’ error, please comment down below with the fix.

Also read: What does ./ mean in Linux?

Yadullah Abidi

Someone who writes/edits/shoots/hosts all things tech and when he’s not, streams himself racing virtual cars.

You can contact him here: [email protected]

Запустите простую команду java в Ubuntu и обнаружите следующие ошибки:

$ java -version

bash: /usr/bin/java: cannot execute binary file: Exec format error

P.S Протестировано с Java 15 и Ubuntu 20

1. Проблема – Скачать неправильная сборка JDK

Ошибка Ошибка формата Exec означает, что мы загружаем неправильную сборку JDK для определенной платформы.

Например, процессор AMD , основанный на архитектуре x86_64 .

$ lscpu

Architecture:                    x86_64
CPU op-mode(s):                  32-bit, 64-bit
Byte Order:                      Little Endian
Address sizes:                   43 bits physical, 48 bits virtual
CPU(s):                          24
On-line CPU(s) list:             0-23
Thread(s) per core:              2
Core(s) per socket:              12
Socket(s):                       1
NUMA node(s):                    1
Vendor ID:                       AuthenticAMD
CPU family:                      23
Model:                           113
Model name:                      AMD Ryzen 9 3900X 12-Core Processor

И мы загружаем Linux/AArch64 сборку JDK.

Попробуйте запустить команду java , и мы столкнемся с приведенной ниже ошибкой:

$ java -version

bash: /usr/bin/java: cannot execute binary file: Exec format error

2. Решение – Разница между процессорами Intel, AMD и ARM

Процессоры Intel и AMD основаны на x86_64 архитектуре; AArch64 предназначен для процессора ARM, который основан на архитектуре ARM .

Дальнейшее чтение |/Quora – В чем разница между Intel, AMD и Процессор ARM

Для процессоров Intel или AMD в Linux, пожалуйста, загрузите JDK Linux/x64 сборка.

Для процессора ARM в Linux, пожалуйста, загрузите JDK Linux/AArch64 сборка.

Рекомендации

  • Википедия – Архитектура ARM
  • Википедия – AMD Ryzen
  • Quora – В чем разница между Intel, AMD и Процессор ARM
  • Проект порта OpenJDK AArch64
  • Зачем использовать архитектуру Arm?

Оригинал: “https://mkyong.com/java/bash-usr-bin-java-cannot-execute-binary-file-exec-format-error/”


  • Метки


    bash, download, file, linux, processor

Понравилась статья? Поделить с друзьями:
  • Java error in pycharm hprof
  • Jam9002 kyocera ошибка
  • Java error hierarchy
  • Jam4311 ошибка как исправить
  • Java error example