Ubuntu – What has changed to prevent Java programs from running via the permission bit

16.04command linejava

I have always set the execute bit on my Java Programs to call them like a regular program without using the -jar argument… just by running the application with the name in the path.

In the past, it only took: chmod +x myjavaprogram.jar, then running it with ./myjavaprogram.jar from the commandline.

It still works on my computers that have the Ubuntu version previous to 16.04. However, it doesn't work on any of my computers that are updated to 16.04.

I can't find any references to the problem, outside of suggestions to ensure the execute bit is set and some references to ensuring to have this installed: sudo apt install binfmt-support

I have never installed the package before, however, in an effort to fix the problem, I ran the installer which confirms it's already installed on Ubuntu by default and has the latest version.

The only other references I'm finding with problems with running java programs is specifications of properly having Java installed (openjdk or oracle). I have both installed with full updates. I also have used sudo update-alternatives --config java to change between the two. They both show the same error at the console.

This is what I get from the two methods:

Using the cli as a regular program:

$ ./HelloWorld.jar
invalid file (bad magic number): Exec format error

Using the -jar argument:

$ java -jar ./HelloWorld.jar 
Hello World

Many of my Java application that is in my /usr/local/bin folder are renamed without the java extension. They still work as a regular program on my computers that has the Ubuntu version previous to 16.04.

Doesn't anyone know how to add this functionality to version 16.04?

Update

Double clicking the applications from the file browser works.

However, I have tens of java apps that I run just like using the normal commandline tools such as, find, top, grep, netstat, and so on. Some of the commands call other java apps that are in the exec path.

Best Answer

The answer is to register the desired binaries with the binfmt-support service.

Studying the difference between what is on my 16.04 installations and my 14.04 installation, I found that the previous Ubuntu version had a larger list when running the command update-binfmts --display.

The list includes a jarwrapper.

Installing the jarwrapper resolved the issue:

$ sudo apt install jarwrapper

The binfmt-support is a service that c an be configured to detect what is needed for running various type of files, including calling Wine to run Windows exe files.

Details for using the binfmt-support service can be found by studying the update-binfmts man pages.

Curious as to why the default support was dropped. But I'm glad to be able to manually restore this support to my computers.

Note

By the way, the program type isn't determined by the extension. It's determined by the application binary header. So the application can be named anything, without an extension.

Related Question