Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

:main does not consider Java .class files #249

kumarshantanu opened this Issue Aug 4, 2011 · 3 comments


3 participants

kumarshantanu commented Aug 4, 2011

When I have Java source files in my project and I specify a Java class (filename Foo.java) to be the :main class, it is not detected. The exception I get is:

Exception in thread "main" java.io.FileNotFoundException: Could not locate Foo__init.class or Foo.clj on classpath:  (NO_SOURCE_FILE:1)

I believe :main should not only look for a .clj or an AOTed .clj file, but also a .class file that is compiled from a Java source file. This will enable me to use Leiningen as a build tool for Java.


technomancy commented Aug 7, 2011

This seems like something we should support. Do you know what's causing the problem?


JulianBirch commented Nov 1, 2011

Taking a look, I'm pretty sure it's as simple as ns-resolve never returns a java class

In run-main: https://github.com/technomancy/leiningen/blob/1.x/src/leiningen/run.clj

I think you'd have to use reflection to find whether myNs.Class was a java class or a clojure namespace.

@technomancy technomancy reopened this Nov 10, 2011


technomancy commented Nov 10, 2011

I've solved this on the compile side. Making it work with lein run is a bit more complicated; I can't get the necessary reflective calls to work:

(defn- run-main
  "Loads the project namespaces as well as all its dependencies and then calls
  ns/f, passing it the args."
  ([project given-main & args]
     (let [[main-ns main-fn] (get-ns-and-fn (symbol given-main))]
       (eval-in-project project `(if-let [v# (ns-resolve '~main-ns '~main-fn)]
                                   (v# ~@args)
                                    ~main-ns "main" (into-array String '~args)))
                        nil nil `(try (require '~main-ns)
                                      (catch FileNotFoundException _#))))))

Results in: No matching method found: main (NO_SOURCE_FILE:1)

Could use a hand with this if you're interested in using the run task with Java classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment