Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a Clojure program

Tags:

say i create a program in clojure and i have to deliver it to a client. the client does have some computer knowledge but he does not know/want to start the repl, load my program, and run it. he wants to double click an exe file or run a shell script

how do i package my program and deliver (the program itself with the clojure jars) ?

like image 549
Belun Avatar asked Aug 29 '10 14:08

Belun


4 Answers

You have a few choices:

  • Compile the program into Java classes, and give one a main method. Package them into an executable jar.
  • Per above, if you use Leiningen then you can assemble everything nicely with lein uberjar, making sure that you have declared a main class.
  • You can alternately package your project into a non-executable jar (no main class) and create a shell script/batch file to execute the proper class e.g. java -cp ./clojure.jar:./myprogram.jar com.my.runthis.class
  • Just package your .clj files into a jar, and use a shell/batch script to start a repl and then automatically issue commands e.g. java -cp ./clojure.jar:./myprogram.jar clojure.main -e "(in-ns 'your-ns)(start-your-program)" -r
like image 129
G__ Avatar answered Sep 21 '22 00:09

G__


Simplest approach would be to let leiningen handle the jar for you it will package everything into a single fat jar thats all you need to deliver just like any other java app. All client has to do is double click on it. If you need an .exe file launch4j can create it for you, it can also handle JRE installation is it is not already installed on the clients machine. You don't need any bash scripts etc.

like image 42
Hamza Yerlikaya Avatar answered Sep 22 '22 00:09

Hamza Yerlikaya


You can use leiningen to create uberjar, as Greg Harman wrote... I personally use maven to create standalone jar with all dependencies, declare main class - this simplify run of it with 'java -jar your-jar-file' command. I also use Izpack to create installers for my programs

like image 25
Alex Ott Avatar answered Sep 20 '22 00:09

Alex Ott


The best approach I have found for doing this is cake bin if you are using cake. It will generate a packaged binary for you (probably same as or similar to launch4j).

like image 30
Damon Snyder Avatar answered Sep 20 '22 00:09

Damon Snyder