How to define project.clj to run lane as well as to replace lein?

I am new to Clojure and I donโ€™t quite understand how to write my project.clj , so it works for both lein repl and lein run . Here it is (all the way: ~/my-project/project.clj ):

 (defproject my-project "1.0.0-SNAPSHOT" :description "FIXME: write description" :dependencies [[org.clojure/clojure "1.3.0"]] :main my-project.core/hello ) 

Then I have my ~/my-project/src/my_project/core.clj file

 (ns my-project.core) (defn hello [] (println "Hello world!") ) 

lein run works fine, but when lein repl starts, I get a FileNotFoundException :

 ~/my-project$ lein run Hello world! ~/my-project$ lein repl REPL started; server listening on localhost port 42144 FileNotFoundException Could not locate hello__init.class or hello.clj on classpath: clojure.lang.RT.load (RT.java:430) clojure.core=> 

How do I edit project.clj to solve this problem? Or do I need to call lein repl differently?

Thanks in advance.

EDIT : tried using lein dep and lein compile but still the same errors

 ~/my-project$ lein version Leiningen 1.7.1 on Java 1.6.0_27 OpenJDK Client VM ~/my-project$ lein deps Copying 1 file to /home/yasin/Programming/Clojure/my-project/lib ~/my-project$ lein compile No namespaces to :aot compile listed in project.clj. ~/my-project$ lein repl REPL started; server listening on localhost port 41945 FileNotFoundException Could not locate hello__init.class or hello.clj on classpath: clojure.lang.RT.load (RT.java:430) 
+7
source share
1 answer

One thing you could do to make it work is to change core.clj to:

 (ns my-project.core (:gen-class)) (defn hello [] (println "Hello world!")) (defn -main [] (hello)) 

And edit project.clj to:

 (defproject my-project "1.0.0-SNAPSHOT" :description "FIXME: write description" :dependencies [[org.clojure/clojure "1.3.0"]] :main my-project.core) 

(:gen-class) tells the compiler to create a Java class for the namespace, and the :main directive in project.clj tells lein run to run the main method in the class, which is given by -main . Why lein repl could not find my-project.core/hello is not clear to me, but I know little about leiningen internals.

+13
source

All Articles