How to run maven app with clojure package from jar

I have the following contents in a file src/main/clojure/za/co/pb/maven_test/test.clj:

(ns za.co.pb.maven-test.test
  (:gen-class))

(defn -main []
  (println "Hello world!"))

I also have a POM that has the necessary dependencies on clojure -maven-plugin with compilation execution.

If I execute the command mvn package, I get the file target/maven-test-1.0-SNAPSHOT.jar, and if I look in the classes folder, I have these files in the folder target/classes/za/co/pb/maven_test:

  • test.class
  • test.clj
  • test__init.class
  • test$loading__4410__auto__.class
  • test$_main.class

This, as far as I know, is suitable.

However, when I run this command:

java -cp target\app-1.0-SNAPSHOT.jar za.co.pb.maven_test.test

I get this:

Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/IFn
Caused by: java.lang.ClassNotFoundException: clojure.lang.IFn
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: za.co.pb.maven_test.test. Program will exit.
+3
source share
4 answers
+5

JAR , . Maven Assembly Plugin , jar-with-dependencies.

+4

If you use leiningen , after creating the flag with lein uberjardo not use java -jar target/your-name.jar, but use java -jar target/your-name-standalone.jar.

The same for boot.

+1
source

Are all dependencies available? I am not familiar with the clojure.lang.IFn class. Is it from an external library? If you specified a dependency with the provided scope?

-2
source

Source: https://habr.com/ru/post/1769425/


All Articles