Search code examples
clojureleiningen

Can I run my command with out lein run?


I currently run a simple cli I wrote by calling: lein run my-cli-command arg --option

How can I call my command without needing to include lein run? This is what i'm after: my-cli-command arg --option

Do I need to convert it to an binary or executable and if so how?


Solution

  • As far as I know, there's no way to run just my-cli-command arg --option.

    You can take lein out of the equation though by creating a Java archive:

    lein uberjar
    

    Then run the jar as you would any other:

    java -jar target/my-cli-command-standalone.jar arg --option
    

    uberjar will name the jar based on what you've called your project in project.clj, and will create a jar that relies on external dependencies, and one that doesn't (standalone).

    Then, as @gary pointed out, you can stick the java - jar ... command in a .bat file, name it whatever you want, then run the bat directly. My bat-Fu is pretty weak, but there's likely a way to pass arguments to the bat and have them passed to the jar so you don't need to hard code the arguments.