Question

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

Was it helpful?

Solution

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

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] ...) 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 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))

By 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 ;).

OTHER TIPS

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

com.explodingdots.core

I also declare main to take an arg vector, not sure if that makes a diference:

(declare main) 
(defn -main [& args]    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top