不能使用Leiningen构建一个jar [英] Can't build a jar using Leiningen

查看:1294
本文介绍了不能使用Leiningen构建一个jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用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任务时,我得到以下输出:


警告:指定:main不包含在:aot中。
隐式AOT:main将在Leiningen 3.0.0中删除。
如果你只需要AOT你的uberjar,考虑添加:aot:all到你的
:uberjar配置文件。
警告:指定的Main-Class在jar中不存在。它可能无法按预期执行。 gen-class伪指令可能在包含main方法的命名空间中丢失。
创建的C:\Users\slomi\IdeaProjects\WaterTimer\target\WaterTimer-1.jar
创建的C:\Users\slomi\IdeaProjects\WaterTimer\ target\WaterTimer-1-standalone.jar


我也尝试过更改函数具有默认名称,并从 defproject 中省略名称:

 (defproject WaterTimer1
:description提醒你喝水的计时器
:主音制作者)

b $ b(:require [general-helpers:as g])

(:import [javax.sound.midi MidiSystem
合成器
MidiChannel])
:gen-class))

(defn -main [& args]
(printlnTest!))

但现在我遇到错误:


错误:找不到或加载主类clojure.main
编译失败:子过程失败


结构是:




  • 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:

Warning: specified :main without including it in :aot. Implicit AOT of :main will be removed in Leiningen 3.0.0. If you only need AOT for your uberjar, consider adding :aot :all into your :uberjar profile instead. Warning: The Main-Class specified does not exist within the jar. It may not be executable as expected. A gen-class directive may be missing in the namespace which contains the main method. Created C:\Users\slomi\IdeaProjects\WaterTimer\target\WaterTimer-1.jar Created C:\Users\slomi\IdeaProjects\WaterTimer\target\WaterTimer-1-standalone.jar

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:

Error: Could not find or load main class clojure.main Compilation failed: Subprocess failed

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆