Idan Arye
Idan Arye

Reputation: 12633

What is wrong with my simple Clojure gen-class script?

I'm trying to learn how to use gen-class in Clojure. I've started with this simple script:

(gen-class :name MyClass :prefix MyClass-)

(defn MyClass-toString[this] "This Is My Class")

(println (MyClass.))

When I try to run it I get

    Exception in thread "main" java.lang.IllegalArgumentException: Unable to resolve classname: MyClass

What am I doing wrong?

Upvotes: 4

Views: 2215

Answers (2)

kotarak
kotarak

Reputation: 17309

You need AOT compilation for gen-class.

Upvotes: 3

runexec
runexec

Reputation: 862

edit, Also, check that the main class name matches the one defined in the lein project file.

Usually you put in the (ns) header of the clj file.

(ns my.namespace
  (:gen-class))

Here's some examples

(gen-class
    :name "some.package.RefMap"
    :implements [java.util.Map]
    :state "state"
    :init "init"
    :constructors {[] []}
    :prefix "ref-map-")

Upvotes: 1

Related Questions