“lein jar”和“lein uberjar”没有正确设置主类
我在我的项目上运行 lein uberjar 并创建了相应的 jar 文件。当我运行 jar 时,会引发 ClassNotFoundException: explodingdots.core
。我指定 explodingdot.core
作为我的主类。我解压了jar文件,对应目录下确实没有core.class
。我忘记了什么?
我的 src/explodingdots/core.clj
中有以下代码,
(ns explodingdots.core (:import (java.awt Color Dimension Graphics2D AlphaComposite RenderingHints) (java.awt.event ActionListener MouseAdapter WindowAdapter) (javax.swing Timer JPanel JFrame)) (:gen-class)) [ ... ] (defn -init[] exploding-dots) (defn -main[_] (let [ed (new explodingdots.core)] (.init ed)))
我的 project.clj
的内容是:
(defproject explodingdots "0.1" :dependencies [[org.clojure/clojure "1.2.0"] [org.clojure/clojure-contrib "1.2.0"]] :main explodingdots.core)
注意: 我正在使用 leiningen 1.3 .1
I ran lein uberjar
on my project and it created the corresponding jar files. When I run the jar a ClassNotFoundException: explodingdots.core
is thrown. I specified explodingdot.core
as my main class. I extracted the jar file and there was indeed no core.class
in the corresponding directory. What did I forget?
I have the following code in src/explodingdots/core.clj
(ns explodingdots.core (:import (java.awt Color Dimension Graphics2D AlphaComposite RenderingHints) (java.awt.event ActionListener MouseAdapter WindowAdapter) (javax.swing Timer JPanel JFrame)) (:gen-class)) [ ... ] (defn -init[] exploding-dots) (defn -main[_] (let [ed (new explodingdots.core)] (.init ed)))
The content of my project.clj
is:
(defproject explodingdots "0.1" :dependencies [[org.clojure/clojure "1.2.0"] [org.clojure/clojure-contrib "1.2.0"]] :main explodingdots.core)
Note: I am using leiningen 1.3.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我解决了原来的问题。承认这一点有点尴尬,但我想为了这篇文章的完整性我必须这么做。我与自己的道路混淆了。我在 Netbeans 项目和 leiningen 项目中有相同的文件。我正在编辑 Netbeans 文件。对不起。
但后来我遇到了另一个问题。找到了主要方法,但我得到了一个
“我尝试更改我的主要方法”
(defn -main [_] ...)
到(defn -main [& args] ...)
就像 Arthur 建议的那样,但这不起作用。为了解决这个问题,我只写了(defn -main[]...)
,没有参数。下一个问题是从
(main)
调用(init)
导致错误。我通过根本不调用(init)
而是直接从(main)
调用(exploding-dots)
来解决这个问题。因此,为了使一切正常工作,我的 src/explodingdots/core.clj 看起来像
通过查看解决方案,我必须思考,为什么我不提前写下来。这是最简单、最直接的方法。也许我需要一个假期;)。
Ok I solved my original problem. It is kind of embarassing to admit it, but I think I have to do it for the sake of completeness of this thread. I got mixed up with my paths. I have the same file within a Netbeans project and in a leiningen project. And I was editing the Netbeans file. Sorry.
But then I had an other problem. The main method is found but I get an
I tried changing my main method from
(defn -main [_] ...)
to(defn -main [& args] ...)
like Arthur suggested but that didn't work. To solve this I wrote just(defn -main[]...)
with no args.The next problem was that calling
(init)
from(main)
resulted in an error. I worked around that by not calling(init)
at all but calling(exploding-dots)
directly from(main)
.So to make everything work my
src/explodingdots/core.clj
looks likeBy looking at the solution I have to think, why didn't I write that right ahead. It is the most simple and most straight forward way. Maybe I need a vacation ;).
我必须向主名称空间添加第三个组件,并将所有内容移至 src 下的 com 子目录中。
我还声明 main 接受一个 arg 向量,不确定这是否有区别:
I had to add a third component to my main name space and move everything into the com subdirectory under src.
I also declare main to take an arg vector, not sure if that makes a diference:
我遇到了这个问题,并通过将
:gen-class
添加到相应的缺失类中来修复它。I ran into this, and fixed it by adding
:gen-class
to the corresponding missing class.