Search code examples
intellij-ideaclojure

clojure newbie, nothing is printed to console in intellij


I created test.clj

I have this code in it:

(ns clojure.examples.hello
  (:gen-class))

(defn -main
  [greetee]
  (println (str "Hello " greetee "!")))

result:

/home/bin/java /tmp/testclj/src/test.clj

(where are my printings? shouldn't they appear here? nothing is printed here)

Process finished with exit code 0

but i get nothing printed out when i run it shouldn't it be printed?


Solution

  • How do you run your code?

    First, you need to compile it:

    (compile 'clojure.examples.hello)
    

    And then:

    java -cp ./classes:clojure.jar clojure.examples.hello Jas
    

    Of course, path depends on your project structure.

    I would say, it is much more easier if you installed IntelliJ Leiningen plugin and trying to run your code with Leiningen.

    With Leiningen, you can do:

    ; run the -main function of a namespace
    lein run -m my.namespace
    

    And it is always a good idea, not to rely on IDEs to run and build your projects.