简体   繁体   中英

Testing Clojure main from REPL

I have defined a -main function in a :gen-class :main true namespace in Clojure. I am trying to test it from the REPL.

My main function looks like this:

(defn -main [& args]
  ; ...
  )

and I am trying to call it with (ns/-main "-x" "foo") , (ns/-main "-x foo") , (ns/-main ["-x" "foo"]) , (ns/-main (into-array String ["-x" "foo"]) , etc., and all give me various errors.

How do I call this function from the REPL and pass in some command line arguments to test it?

Thanks.

I tried to reproduce it:

(defn -main [& args]
  (apply str args)
  )

Then called like:

(-main "a" "b" "c")

And it evaluated to:

"abc"

As it should..

Be sure to check are you using the right namespace identifier, also see if anything weird is happening inside your -main function, like using a string as a number..

Also, it wouldn't hurt to see your error message on this..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM