OlegTheCat
OlegTheCat

Reputation: 4513

How to AOT compile a single clojure file using clj tool? (without deps.edn file)

Let's say I have the following file:

hello/core.clj:

(ns hello.core)

(println "Hello")

Is it possible to AOT compile this file to classfiles using a clj tool without using any "project"-like setup? I've tried something like this:

$ clj -e '(compile "hello/core")'

but am getting an error about unability to locate hello/core.clj file.

Upvotes: 2

Views: 402

Answers (1)

Taylor Wood
Taylor Wood

Reputation: 16194

Looks like clj's default expectation is for source files to be under src directory (from the guide):

By default, the clj tool will look for source files in the src directory, so create the src directory and declare your program at src/hello.clj

And for compile to work, *compile-path* (defaults to "classes") must also exist:

$ mkdir classes
$ tree
.
├── classes
└── src
    └── hello
        └── core.clj

$ test clj -e "(compile 'hello.core)"
Hello
hello.core

Then your class files should be in classes directory.

Upvotes: 3

Related Questions