问题描述
我想使用Intellij的Cursive中的Leiningen插件从我的裸机Clojure项目中创建一个独立的jar。
要创建项目创建了project.clj文件,打开它,Cursive提供将其作为项目导入。
project.clj:
(defproject WaterTimer1
:description提醒你喝水的计时器
:主音制作者/ b
tone-producer.clj:
(ns tone-producer
(:require [general-helpers:as g])
(:import [javax.sound.midi MidiSystem
Synthesizer
MidiChannel])
(:gen-class))
(defn main [& args]
(printlnTest!
当我运行uberjar任务时,我得到以下输出:
我也尝试过更改主
函数具有默认名称,并从 defproject
中省略名称:
(defproject WaterTimer1
:description提醒你喝水的计时器
:主音制作者)
b $ b(:require [general-helpers:as g])
(:import [javax.sound.midi MidiSystem
合成器
MidiChannel])
:gen-class))
(defn -main [& args]
(printlnTest!))
但现在我遇到错误:
结构是:
- WaterTimer
- src
- tone-producer.clj
- project.clj
- 目标
此处的任何指导都不胜感激。
- 我放了
- 错误:无法找到或加载主类clojure.main编译失败
- 您未包含clojure依赖项[1]
-
:gen-class
需要AOT-正如Sanchayan指出的
-
project.clj
(defproject WaterTimer0.0.1
:description提醒你喝水的计时器
:dependencies [[org.clojure / clojure1.8.0 ]] ;; < - [1]
:main tone-producer
:aot [tone-producer]);; < - [2]
src / tone_producer.clj - USE'_' ' - 'in the filename
(ns tone-producer
(:import [javax.sound .midi MidiSystem
Synthesizer
MidiChannel])
(:gen-class))
(defn -main [& args]
(println Test!))
结果:
$ lein uberjar
编译音调生成器
编译音调生成器
创建... / watertimer / target / WaterTimer-0.0.1.jar
Created ... / watertimer / target / WaterTimer-0.0.1-standalone.jar
$ java -jar target / WaterTimer-0.0.1-standalone.jar
Test!
lein new< name>
并将其导入Cursive /其他IDE选择。
I'm trying to make a stand alone jar from my bare-bones Clojure project using the Leiningen plugin in Intellij's Cursive.
To create the project, I just created the project.clj file, opened it, and Cursive offered to import it as a project.
project.clj:
(defproject WaterTimer "1"
:description "A timer that reminds you to drink water"
:main tone-producer/main)
tone-producer.clj:
(ns tone-producer
(:require [general-helpers :as g])
(:import [javax.sound.midi MidiSystem
Synthesizer
MidiChannel])
(:gen-class))
(defn main [& args]
(println "Test!"))
When I run the "uberjar" task, I get the following output:
I also tried changing the main
function to have the default name, and omit the name from the defproject
:
(defproject WaterTimer "1"
:description "A timer that reminds you to drink water"
:main tone-producer)
(ns tone-producer
(:require [general-helpers :as g])
(:import [javax.sound.midi MidiSystem
Synthesizer
MidiChannel])
(:gen-class))
(defn -main [& args]
(println "Test!"))
But now I get the error:
The structure is:
- WaterTimer
- src
- tone-producer.clj
- project.clj
- target
Any guidance here would be appreciated.
解决方案 After a bit of fiddling
- I dropped
(:require [general-helpers :as g])
since its not necessary to demostrate the issue - Error: Could not find or load main class clojure.main Compilation failed
- you didn't include the clojure dependency [1]
:gen-class
needs AOT - as Sanchayan pointed out- see [2]
project.clj
(defproject WaterTimer "0.0.1"
:description "A timer that reminds you to drink water"
:dependencies [[org.clojure/clojure "1.8.0"]] ;; <- [1]
:main tone-producer
:aot [tone-producer]) ;; <- [2]
src/tone_producer.clj - USE '_' instead of '-' in the filename
(ns tone-producer
(:import [javax.sound.midi MidiSystem
Synthesizer
MidiChannel])
(:gen-class))
(defn -main [& args]
(println "Test!"))
Result:
$ lein uberjar
Compiling tone-producer
Compiling tone-producer
Created .../watertimer/target/WaterTimer-0.0.1.jar
Created .../watertimer/target/WaterTimer-0.0.1-standalone.jar
$ java -jar target/WaterTimer-0.0.1-standalone.jar
Test!
Generally I'd recommend to init a project with lein new <name>
via command line and the import it into Cursive/Other IDE of choice.
这篇关于不能使用Leiningen构建一个jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
08-13 18:57