如何从 jar 运行 maven 打包的 clojure 应用程序

发布于 2024-09-27 19:50:15 字数 1400 浏览 1 评论 0原文

我在 src/main/clojure/za/co/pb/maven_test/test.clj 文件中有以下内容:

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

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

我还有一个 POM,它对 clojure-maven-plugin 具有必要的依赖关系,其中编译执行。

如果我执行 mvn package 命令,我会得到一个 target/maven-test-1.0-SNAPSHOT.jar 文件,如果我查看类文件夹,我会在其中找到这些文件文件夹target/classes/za/co/pb/maven_test

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

据我所知,这是合适的。

但是,当我运行以下命令时:

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

我得到以下信息:

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.

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

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

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

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

If I execute a mvn package command, I get a target/maven-test-1.0-SNAPSHOT.jar file 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 appropriate.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

笑梦风尘 2024-10-04 19:50:15

类路径中没有 clojure jar。您可以按照 Stuart 的响应嵌入它们,或者如果您不喜欢将所有依赖项嵌入到单个 jar 中,则可以使用依赖项插件和 jar 插件来使其正常工作。

请参阅:http://groups.google.com/group/enclojure/msg/87159854fcb0e708 进行摘要(注意,链接的帖子中有一个拼写错误,该包应称为“foo”)。

You don't have the clojure jars in the classpath. You can either embed them as per Stuart's response, or if you don't like having all the dependencies embedded in a single jar, you can use the dependency plugin and the jar plugin to get this working nicely.

See: http://groups.google.com/group/enclojure/msg/87159854fcb0e708 for a summary (note, there's a typo in the linked post, the package should be called "foo").

末骤雨初歇 2024-10-04 19:50:15

您需要生成一个包含项目所有依赖项的 JAR 文件。 Maven Assembly Plugin 使用内置的 jar-with-dependencies 描述符为您完成此操作。

You need to generate a JAR file file that includes all the dependencies of your project. The Maven Assembly Plugin does this for you, using the built-in jar-with-dependencies descriptor.

小巷里的女流氓 2024-10-04 19:50:15

如果您使用 leiningen,在使用 lein uberjar 生成 jar 后,请勿使用 < code>java -jar target/your-name.jar,但使用 java -jar target/your-name-standalone.jar

boot 也是如此。

If you are using leiningen, after generating the jar with lein uberjar, do not use java -jar target/your-name.jar, but use java -jar target/your-name-standalone.jar.

Same thing for boot.

烟花易冷人易散 2024-10-04 19:50:15

所有依赖项都可用吗?我不熟悉 clojure.lang.IFn 类。是来自外部图书馆吗?如果是,您是否用提供的范围标记了依赖关系?

Are all dependencies available ? I'm not familiar with the clojure.lang.IFn class. Is it from an external library? If it is did you marked the dependency with the provided scope?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文