Mateusz Kubuszok
Mateusz Kubuszok

Reputation: 27535

Leiningen fails to work with newly generated project

I have a problem running Leiningen on Windows (in both Cygwin and CMD).

When at first I generated project:

$ lein new app leintest
Generating a project called leintest based on the 'app' template.

and then I tried to run it:

$ cd leintest/
$ lein run
$

it shown no result. -main function has println:

$ cat src/leintest/core.clj
(ns leintest.core
  (:gen-class))

(defn -main
  "I don't do a whole lot ... yet."
  [& args]
  (println "Hello, World!"))

and it is pointed by project.clj:

$ cat project.clj
(defproject leintest "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.6.0"]]
  :main ^:skip-aot leintest.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}})

So basically I am unable to run template project. What is more I am also unable to build uberjar:

$ lein uberjar
Warning: The Main-Class specified does not exist within the jar. It may not be executable as expected. A gen-class directive may be missing in the namespace which contains the main method.
Created E:\Workspaces\leintest\target\uberjar\leintest-0.1.0-SNAPSHOT.jar
Created E:\Workspaces\leintest\target\uberjar\leintest-0.1.0-SNAPSHOT-standalone.jar

As I understand it doesn't even find main class. When I tried to debug that with repl I learned that REPL server launch timed out..

My version of Leningen is Leiningen 2.4.3 on Java 1.7.0_51 Java HotSpot(TM) 64-Bit Server VM. I see the same behavior whether I use lein script (Cygwin) or lein.bat (CMD).

What can I do to figure out where things break?

Upvotes: 2

Views: 764

Answers (2)

Daniel
Daniel

Reputation: 895

Incidentally, I had this same problem but my environmental variables were set correctly. In my case, unlike the questioner, I had failed to add the :gen-class directive in a namespace declaration in the file with the main method. It was resolved by appending the second line below to the namespace declaration:

(ns async-test.core
  (:gen-class :main true)
  (:require [clojure.core.async :as async]))

Upvotes: 2

Mateusz Kubuszok
Mateusz Kubuszok

Reputation: 27535

The problem was caused by a JAVA_PATH system variable.

I have 2 Java installations - standard one and portable one. Standard one added itself to PATH variable so that java would execute C:\Program Files\Java\jre7\bin\java.exe.

In Cygwin I added JAVA_PATH pointing to the portable installation and added its directory to the path (SET PATH=%PATH%;%JAVA_PATH%\bin). However since that directory occurred after the one added by nonportable installation it was ignored. Mismatch between JAVA_PATH variable and directory in PATH made lein script call fail. Meanwhile in CMD I had no JAVA_PATH set at all.

When I made sure that JAVA_PATH is set correctly and it is added to the PATH before the standard installation (SET PATH=%JAVA_PATH%\bin;PATH) everything started to work.

Upvotes: 2

Related Questions