GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
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
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.
This seems like something we should support. Do you know what's causing the problem?
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.
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:
"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)]
~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.