How to create a command-line executable in Clojure

If you really want to do it, you can uuencode the jar file (or any other binary file) in a bash executable, see this for an example: Embed a Executable Binary in a shell script


It sounds like you're just trying to bootstrap your app from a script using cleaner syntax. This might be most easily done like so:

create a new bash script called myprogram:

#!/usr/bin/bash
# pass whatever command line args you have down through the script
java -jar myjar.jar

give it execute permissions

chmod +x myprogram

run it

./myprogram (with whatever params)

If you want to get rid of the ./ you'll need to move things around so the script gets picked up by your PATH.

Keep in mind that you're not creating a platform specific binary executable. Doing so would pretty much defeat the purpose of using the jvm in the first place. You'd just be invoking it through an extra layer of indirection.


Now that GraalVM has matured a little bit, you may want to consider compiling your application to a binary executable.

There's a good tutorial of how to accomplish that here.

Tags:

Java

Ruby

Clojure