Sunday, August 18, 2013

GUIDE: Directly Executable JAR File

Java is great, but having to type java -jar program.jar gets annoying. Why can't you run it like any other program, with ./program.jar? Well, you can, and it's incredibly simple!

echo '#!/usr/bin/java -jar' | cat - Program.jar>Program
chmod +x Program

Tada! That's it! Program.jar has now been converted to a file Program, which can be run using ./Program! You can even send the Program file to someone else, and they will also be able to run it the same way!

This works because the ZIP file format upon which the JAR format is based is quite resilient in allowing extra data (in this case, the hash-bang) at the beginning of archives.

It's important to note, however, that the resulting file will not be able to be read by file-roller, unless it is renamed to have a .zip extension.

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home