how to run executable JAR files

Asked by David White

I have two development machines, a desktop and a laptop. Both run Quantal 64 and OpenJDK 7 / Iced Tea. My desktop can run exectuable JAR files but my laptop cannot run the same files. I've tried uninstalling and reinstalling java but to no avail. Any advice?

On the laptop I get the following on a terminal:

$ ./kedar.jar
./kedar.jar: line 1: $'PK\003\004': command not found
./kedar.jar: line 2: $'\b\200[fA': command not found
./kedar.jar: line 3: �CN��META-INF/MANIFEST.MFM�0
                                                  E�H���0�!t+݀: No such file or directory
./kedar.jar: line 4: syntax error near unexpected token `$'\251\2340\360\367\244\210\241\213u\037\307\226+t\346I!\352\Eq0\336\345j''
./kedar.jar: line 4: `���Lkڔ(��0������uǖ+t�I!q0��j ���$ŀuG*e���J�� #d�l��Z�Ό�%Uz
<cL�s)*4N�Cȕ���}��H��B\�cC
                                             �k���sR�ZOHA��m�8���S?@_0v��Ezvꥐ�
                                                                              PK'

Running it with strace I get:

$ strace ./kedar.jar
execve("./kedar.jar", ["./kedar.jar"], [/* 43 vars */]) = -1 ENOEXEC (Exec format error)
dup(2) = 3
fcntl(3, F_GETFL) = 0x8002 (flags O_RDWR|O_LARGEFILE)
fstat(3, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f123d27c000
lseek(3, 0, SEEK_CUR) = -1 ESPIPE (Illegal seek)
write(3, "strace: exec: Exec format error\n", 32strace: exec: Exec format error
) = 32
close(3) = 0
munmap(0x7f123d27c000, 4096) = 0
exit_group(1)

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu bash Edit question
Assignee:
No assignee Edit question
Solved by:
David White
Solved:
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

You need a java plugin. The file is not a Linux binary.

Can you give the output of:

lsb_release -a; uname -a; java -version

Thanks

Revision history for this message
David White (cppege-david-9ei9ny) said :
#2

Thank you for the response.

Java is installed and working - I'm developing on Eclipse and java -jar kedar.jar works as expected.

Here is the information you asked for:

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.10
Release: 12.10
Codename: quantal
Linux Aspire-5750 3.5.0-18-generic #29-Ubuntu SMP Fri Oct 19 10:26:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
java version "1.7.0_09"
OpenJDK Runtime Environment (IcedTea7 2.3.3) (7u9-2.3.3-0ubuntu1~12.10.1)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#3

Then run:

java ./kedar.jar

And it will run

Revision history for this message
David White (cppege-david-9ei9ny) said :
#4

I know how to do that. What I don't know is how to fix the kernel not running the executable JAR file (via java) like it's supposed to. This has been a feature of the Linux kernel for a while now and it works on my other computer. execve should be returning 0, not -1.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#5

If you mark the java file asexecutable then the interpretter will try and run it as a Linux binary. This is normal. You could right click the file and associate jar files with /usr/bin/java and then when you double click the file it will open with /usr/bin/java (remember to tell the OS to remember the pairing).

Revision history for this message
David White (cppege-david-9ei9ny) said :
#6

No it's not normal. Try it out yourself with an executable JAR. Here's the strace of running a JAR file on my desktop with identical configuration (same java, running Quantal). It works on that.

$ strace ./kedar.jar
execve("./kedar.jar", ["./kedar.jar"], [/* 44 vars */]) = 0
brk(0) = 0xb3b000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fec08b05000

As you can see execve returns 0. What happens is that the java app runs just like any other binary.

Check out the kernel documentation:
http://www.kernel.org/doc/Documentation/java.txt

What I need to do is fix it on my laptop because I am developing a java executable and my laptop has developed this problem.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#7

andy@D420:~/Downloads$ java -version
java version "1.7.0_09"
Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode)
andy@D420:~/Downloads$ ls
minecraft.jar
andy@D420:~/Downloads$ chmod +x ./minecraft.jar
andy@D420:~/Downloads$ ./minecraft.jar
bash: ./minecraft.jar: cannot execute binary file
andy@D420:~/Downloads$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04.1 LTS
Release: 12.04
Codename: precise
andy@D420:~/Downloads$ uname -a
Linux D420 3.2.0-32-generic-pae #51-Ubuntu SMP Wed Sep 26 21:54:23 UTC 2012 i686 i686 i386 GNU/Linux

Your witness

Revision history for this message
David White (cppege-david-9ei9ny) said :
#8

david@ubuntu-desktop:~/Workspace$ ls *.jar
hello.jar
david@ubuntu-desktop:~/Workspace$ ./hello.jar
hello world
david@ubuntu-desktop:~/Workspace$ java -jar hello.jar
hello world

You can download from www.netriver.co.uk/hello.jar

Source code:

package hello;
public class helloWorld {
 public static void main(String[] args) {
  System.out.println("hello world");
 }
}

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#9

andy@D420:~$ chmod +x ./hello.jar
andy@D420:~$ ./hello.jar
bash: ./hello.jar: cannot execute binary file
andy@D420:~$ ls
Desktop Documents Downloads Dropbox hello.jar Music Pictures Public Templates Videos

Revision history for this message
David White (cppege-david-9ei9ny) said :
#10

Andrew, unless you know why it works on my desktop and not on my laptop, please stop marking this as answered. I'm not trying to fix it on your computer but I'm trying to find someone who knows about this issue. Perhaps it doesn't work on your computer but it works on at least one of mine. I'm not making it up and this is a feature of Linux (see link to kernel docs previously posted).

Does anybody know how to solve this problem?

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#11

It is marked as answered as I am answering you. It will end when it is marked as 'solved' which only you can do. What your system is doing is not normal, JAR files are to be ran against Java, they are not understandable by the bash interpreter so it needs an extra file to open it. If you try and do the same with openoffice apps it will also kick out an error message as the file is not something bash can deal with, however you can launch an application to open the file and it will display properly.

I doubt you will get an answer here but there is some weird config on your system which is not standard for the bash interpretter to be able to understand JAR files. I even grabbed the file you linked and ran it as you did. It doesn't work as it's not normal.

I suggest you run:

env

To see what is different and that will give you a clue.

Revision history for this message
David White (cppege-david-9ei9ny) said :
#12

Sorry about the misunderstanding - it was making me frustrated!

I found the answer. binfmt-support keys into the binfmt kernel module to provide java executable support. I need to do the following on my laptop:

sudo apt-get install binfmt-support

The reason it's on my desktop and not my laptop is because I've got packages on my desktop that brought it in. If you install eclipse, wine, or one of a a host of others, binfmt-support is installed as well. This is how the kernel handles foreign binaries such as Windows and Java. Nothing weird or not normal about this - wine is often installed as default and Eclipse is probably the most popular IDE out there.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#13

So you added an extra bit of functionality to the OS. The normal functionality I was showing you IS normal, like I said. If you add extra stuff like the package you said, then it is no longer normal.

Revision history for this message
David White (cppege-david-9ei9ny) said :
#14

Normal? Why are you going on about normal? Let's fix problems, not argue the toss on what is normal. It's in Quantal packages and it's a common package to have installed. Perfect for this forum.