莱宁根有多个主要班级 [英] leiningen with multiple main classes
问题描述
我想用leiningen有两个主要的类(或更多类),然后能够在java命令行中选择哪个.例如,我有:
I'd like to have two main classes (or more) with leiningen, and then be able to choose which one at the java command line. For example I have:
(ns abc (:gen-class))
(defn -main [] (println "abc"))
(ns def (:gen-class))
(defn -main [] (println "def"))
在project.clj中具有:
With a project.clj having:
(defproject my-jar "0.0.1"
:description "test"
:dependencies [
]
:main abc)
然后用lein uberjar
构建,然后运行:
Then I build with lein uberjar
, and run:
java -cp my-jar-0.0.1-standalone.jar abc
java -cp my-jar-0.0.1-standalone.jar def
我知道,当我在project.clj中指定:main abc
时,它已将其作为清单中的主类调用,但是如果没有放置 something .但是,无论哪种方式,当我尝试运行'def'main时,都找不到一个类:
I get it that when I specified :main abc
in the project.clj it was calling that out as the main-class in the manifest, but I couldn't get it to run without putting something. But either way when I try to run the 'def' main, I get a class not found:
Exception in thread "main" java.lang.NoClassDefFoundError: def
推荐答案
我将:aot [abc def]
添加到project.clj中以生成编译后的代码,并且可以正常工作.
I added :aot [abc def]
to the project.clj to generate compiled code and it worked.
这篇关于莱宁根有多个主要班级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!