I am reading the documention on clojure.org about compilation, the last part gen-class examples. I do the examples and then when trying to run it as java app with:
java -cp ./classes:clojure.jar clojure.examples.hello Fred
in the terminal i get :Error: Could not find or load main class clojure.examples.hello
. Can someone help?Can someone introduce where to learn about gen-class and :gen-class, i find not much documentation on web
Clojure.org documentation on compilation and gen-class
101 views Asked by AudioBubble At
1
The command
java -cp ./classes:clojure.jar tst.core
from your base+system+user+dave is almost correct. Thejava.lang.NoClassDefFoundError: clojure/lang/IFn
error is because the JVM cannot find the Clojure classes as there is noclojure.jar
file in thebase+system+user+dave
directory, so you need to specify the correct path for the clojure.jar file.As you are using
lein
, it downloads your project dependencies to your local repository. One of the dependencies will be Clojure itself, so assuming you are on iOS/Linux and that your lein project.clj has a dependency with clojure 1.7.0, the command to run from the base+system+user+dave directory will be:As this gets quite annoying once you have more than one dependency, I would suggest to use
lein uberjar
that will create a file in thetarget
directory called your-project-name-standalone.jar that will have all required classes, so to run it from the command line go to the target directory and run something like :To understand more about how the classpath works in the JVM, you can start with Wikipedia