OS: Oracle Linux 6.5 x86_64
Issue: Oracle jdk1.7.0 x86_64 jexec startup script fails to provide direct execution of standalone jar files
I have been in doubt whether to post this topic on one of numerous OTN Java forums or here. Taking into consideration however that the issue is related to binfmt_misc (a capability of linux kernel to recognize file format of an executable, allowing it to be executed directly), I decided to put it on this forum.
Oracle jdk1.7.0 comes with jexec init script that fails to provide direct execution of standalone jar files, although it creates virtual jexec in mounted binfmt_misc. According to official Oracle JDK documentation page, "a new service script, named jexec, is added to /etc/init.d. This script allows users to directly execute any standalone JAR file that has an execution permission set. This can be demonstrated using an example from the JDK:
cd /usr/java/jdk1.6.0/demo/jfc/SwingSet2
chmod +x SwingSet2.jar
/SwingSet2.jar
"
Following this example and trying to execute SwingSet2.jar directly, I am getting the severe error message:
[root@proton ~]# cd /usr/java/jdk1.7.0_60/demo/jfc/SwingSet2
[root@proton SwingSet2]# chmod +x SwingSet2.jar
[root@proton SwingSet2]# ./SwingSet2.jar
invalid file (bad magic number): Exec format error
The same happens using jexec binary:
[root@proton SwingSet2]# /usr/java/jdk1.7.0_60/lib/jexec SwingSet2.jar
invalid file (bad magic number): Exec format error
This happens regardless of which kernel currently is running - 2.6.32 or 3.8.13. The normal execution 'java -jar SwingSet2.jar' however works correctly as expected. Note that binfmt_misc is mounted and contains 3 virtual files:
[root@proton ~]# cat /proc/sys/fs/binfmt_misc/jexec
enabled
interpreter /usr/java/default/lib/jexec
flags:
offset 0
magic 504b0304
[root@proton ~]# cat /proc/sys/fs/binfmt_misc/status
enabled
The third virtual file /proc/sys/fs/binfmt_misc/register is empty.
I don't know whether the issue existed in OL5.x x86_64 or not, as I didn't use Oracle JDK in OL5.x, but a friend of mine, who has 32-bit Oracle JDK installed on 32-bit OL5.10, tells me that direct execution of jar files always succeeds.
Is this known issue/bug in OL6.5 kernels, or something is wrong or missing in my OL6.5 installation?