lein run vs lein trampoline run vs uberjar
Asked Answered
A

1

9

What is the difference between lein run, lein trampoline run and deploying a clojure app as uberjar? Is there any performance difference?

If I do a lein run/lein trampoline run I can just ssh into the server and pull my changes from git, without needing to restart the app, the same is not true for uberjar. In case of uberjars, for every change I need to build and deploy the app.

Thanks in advance.

Angular answered 24/2, 2016 at 7:10 Comment(0)
D
19

All three of them will by default not handle your code changes in real time.

  • lein run: executes the -main function of the targeted or default namespace. Lein runs through out the full execution of that main methods so if your main function creates a web servers, then the leiningen process also stays up the whole time.
  • lein trampoline: executes the -main function as a separate process, so that the main leiningen process can exit and therefore you only have one process running
  • lein uberjar: creates a standalone jar file, so that any other user does not need to have lein installed to run your code. (or any of the source files). To run the jar, you execute java -jar myjarname.jar which contains all the source and all the dependencies.

If you are working with ring, then lein-ring has a development mode that can be started this way:

   lein ring server

which will indeed to code reloading for you.

EDIT: which one to use in production ?

Assuming here that *production* means delivering a bundled version of your code to a user

Creating a jar with lein uberjar and make your final product independent of the build tool is usually the preferred way.

Dismast answered 24/2, 2016 at 7:26 Comment(2)
So given the above methods, which one should be used for production and why? ThanksAngular
Which one should be use for production highly depends on the environment you have and what you want to do. But a general recommendation: on a production system it's always best to have a setup, that does not always check whether files have been modified. This costs performance. So for production it's fine when you have to restart the app to get changes to the running code.Kendricks

© 2022 - 2024 — McMap. All rights reserved.