"lein jar" and "lein uberjar" do not set the main class properly

I executed lein uberjar in my project and created the corresponding jar files. When I start the jar, a ClassNotFoundException: explodingdots.core is thrown. I pointed out explodingdot.core as my main class. I extracted the jar file and there really was 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 contents of my project.clj :

  (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

+4
source share
2 answers

Ok, I solved my original problem. It is embarrassing to admit it, but I think I should do it for the sake of completeness of this topic. I messed up with my ways. I have the same file in the Netbeans project and in the leiningen project. And I edited the Netbeans file. Unfortunately.

But then I had another problem. The main method is found, but I get

  java.lang.IllegalArgumentException: Wrong number of args (0) passed to: core $ -main

I tried changing my main method from (defn -main [_] ...) to (defn -main [& args] ...) as Arthur suggested, but that didn't work. To solve this problem, I wrote simply (defn -main[]...) with no arguments.

The next problem was that calling (init) from (main) led to an error. I worked on this without invoking (init) at all, but invoking (exploding-dots) directly from (main) .

So for everything to work, my src/explodingdots/core.clj looks like

  (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 -main [] (exploding-dots))

After looking at the solution, I should think about why I did not write it right now. This is the easiest and most direct way. Maybe I need a vacation;).

+5
source

I had to add a third component to my main namespace and move everything to the com subdirectory under src.

 com.explodingdots.core 

I also declare that main accepts the arg vector, not sure if this makes a difference:

 (declare main) (defn -main [& args] 
+2
source

All Articles