It would be handy to be able to start Java programs by just calling the class file from the terminal (and have it running it the terminal when double-clicked in GUI, but this is less important). I so far only help myself with the following ad hoc fix:
alias cs='java charstat.Charstat'
Linux recognises the files as Java:
charstat/Charstat.class: compiled Java class data, version 52.0 (Java 1.8)
So is there a way to have the call hard-wired? Ubuntu 16.04 here, but general answers welcome.
End of the question, troubleshooting section starts.
UPDATE
So far the most promising line of action is the one proposed by Gilles. So I ran:
echo ":java-class:M:0:cafebabe::/usr/bin/java:" | sudo tee /proc/sys/fs/binfmt_misc/register
Now,
tomasz@tomasz-Latitude-E4200:~/Desktop$ cat /proc/sys/fs/binfmt_misc/java-class enabled interpreter /usr/bin/java flags: offset 0 magic 6361666562616265
But,
tomasz@tomasz-Latitude-E4200:~/Desktop$ ./Void.class bash: ./Void.class: cannot execute binary file: Exec format error
This was done on Ubuntu 14.04. It has:
binfmt-support/trusty,now 2.1.4-1 amd64 [installed,automatic] Support for extra binary formats
which I think was not installed automatically on 16.04 if that matters.
Yesterday already, following Mark Plotnick's comment, I wrestled with this guide, to no avail. It introduced a wrapper at /usr/local/bin/javawrapper
, which Gilles' solution doesn't contain. That's for Arch Linux though.
UPDATE 2 (Ubuntu 16.06)
On 16.06:
tomasz@tomasz-Latitude-E4200:~/Desktop/io$ cat /proc/sys/fs/binfmt_misc/Java enabled interpreter /usr/local/bin/javawrapper flags: offset 0 magic cafebabe
And,
tomasz@tomasz-Latitude-E4200:~/Desktop/io$ ./Nain.class bash: ./Nain.class: No such file or directory
UPDATE 3
After echo ":java-class:M:0:\xca\xfe\xba\xbe::/usr/bin/java:" | sudo tee /proc/sys/fs/binfmt_misc/register
:
tomasz@tomasz-Latitude-E4200:~/Desktop/io$ java Main Please input the file location and name. ^Ctomasz@tomasz-Latitude-E4200:~/Desktop/io$ ./Main.class Error: Could not find or load main class ..Main.class
For the record:
tomasz@tomasz-Latitude-E4200:/proc/sys/fs/binfmt_misc$ cat java-class enabled interpreter /usr/bin/java flags: offset 0 magic cafebabe