clj
Run Clojure programs or start a REPL
TLDR
Start a REPL (interactive shell)
Execute a function
Run the main function of a specified namespace
Prepare a project by resolving dependencies, downloading libraries, and making/caching classpaths
Start an nREPL server with the CIDER middleware
Start a REPL for ClojureScript and open a web browser
SYNOPSIS
clj [options] [arguments]
PARAMETERS
-Sdeps edn-map
Use specified dependency map.
Overrides dependencies listed in the deps.edn file.
-Srepro
Enter a REPL without reading a program from STDIN or file.
-Scopy-deps
Prints the class path dependencies to standard output. Useful for integration with other tools.
-Spath
Prints class path to standard output, and exits.
-Sforce
Force dependency refresh.
-Aalias-map
Alias expansion map.
-Ttool-alias
Invoke specified tool alias.
-Xalias-map
Run specified tool alias.
-Jjvm-option
Pass jvm options to clojure invocation.
file
Execute Clojure code from a file.
-
Execute Clojure code from standard input (STDIN).
'clojure-code'
Execute the given clojure-code directly.
DESCRIPTION
The `clj` command is a versatile tool designed to execute Clojure code directly from your terminal. It leverages the Clojure CLI tools to compile, load, and run Clojure scripts or programs specified as arguments. This allows for rapid prototyping, scripting, and the execution of Clojure-based utilities without the need for a full-fledged project setup.
`clj` effectively bootstraps a Clojure environment, handling classpath management and dependencies behind the scenes, simplifying the process of working with Clojure code. It supports various input methods, including direct code execution, file loading, and REPL interaction. Users can leverage it for tasks ranging from simple data transformations to more complex application logic.
The command implicitly uses `deps.edn` files (if present) for dependency management, enabling easy integration with existing Clojure projects. This makes it an invaluable tool for Clojure developers, scripting enthusiasts, and anyone seeking to integrate Clojure code into their command-line workflow. Its ease of use and powerful features make it a valuable asset for both beginners and experienced Clojure developers.
DEPENDENCIES
The `clj` command utilizes `deps.edn` files to manage dependencies. If a `deps.edn` file is present in the current directory or parent directories, `clj` will automatically resolve and include the specified dependencies in the classpath.
REPL
With the `-Srepro` command option a REPL (read-eval-print loop) can be started. This allows for interactive evaluation and testing of Clojure code.
The REPL is a vital part of Clojure development, enabling immediate feedback and experimentation.
HISTORY
The `clj` command is part of the Clojure CLI tools, a relatively recent development aimed at simplifying Clojure development workflows. It provides a streamlined way to execute Clojure code without needing a full-fledged project setup with build tools like Leiningen or Boot. Its development stemmed from the need for a more lightweight and flexible approach to running Clojure code, especially for scripting and experimentation. The `clj` command has become increasingly popular due to its ease of use and integration with the Clojure ecosystem, enabling faster development cycles and easier adoption of Clojure.