Fork me on GitHub
#leiningen
<
2015-09-24
>
jmglov08:09:50

Hi, is anyone around who can help me with a Cannot run program "java" issue?

jmglov08:09:36

I'm running lein 2.5.3 with the 1.8.0_60 Oracle JDK, and unless I set :java-cmd in my profile, I get this when running lein:

Compilation failed: Cannot run program "java" (in directory "/home/jmglov/Documents/code/origin-shield-test"): error=2, No such file or directory

jmglov08:09:05

But I have java in my path, and the environment set up:

: jmglov@laurana; which java
/home/jmglov/Software/jdk/bin/java
: jmglov@laurana; env | grep 'JAVA\|JDK'
JAVA_HOME=/home/jmglov/Software/jdk
JAVAC=/home/jmglov/Software/jdk/bin/javac
JDK_HOME=/home/jmglov/Software/jdk
: jmglov@laurana; java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

jmglov08:09:01

This started happening after I moved to a new laptop. The strange thing is that I am using the same home directory as before, so nothing should have changed.

jmglov08:09:51

I upgraded leiningen to the latest version (I was using a previous 2.x version before, though I don't remember exactly which), but same problem.

ian08:09:03

@jmglov: what do you set :java-cmd to?

ian08:09:09

(that makes it work)

ian08:09:19

hm, never mind.

ian08:09:47

jmglov: do you have something funny set in the project's profiles.clj or ~/.lein/profiles.clj?

jmglov08:09:00

@ian: Here's my complete ~/.lein/profiles.clj:

{:user {:dependencies [[org.clojure/tools.nrepl "0.2.10"]
                       [pjstadig/humane-test-output "0.6.0"]]
        :injections [(require 'pjstadig.humane-test-output)
                     (pjstadig.humane-test-output/activate!)]
        :plugins [[cider/cider-nrepl "0.9.1"]
                  [lein-pprint "1.1.1"]
                  [lein-try "0.4.1"]]
        :java-cmd "/home/jmglov/Software/jdk/bin/java"}}

ian08:09:20

and it doesn't work if you remove the :java-command key?

jmglov08:09:40

And the project.clj in question:

(defproject origin-shield-test "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url ""
  :license {:name "Eclipse Public License"
            :url ""}
  :dependencies [[org.clojure/clojure "1.7.0"]
                 [clj-http "2.0.0"]]

  :main origin-shield-test.core

  :profiles {:uberjar {:aot :all
                       :java-cmd "/home/jmglov/Software/jdk/bin/java"}})

jmglov08:09:20

But this problem has shown up in all of my lein projects, so it isn't specific to this project.

jmglov08:09:40

Removing :java-cmd breaks it.

jmglov08:09:31

I poked around in the lein source, but I can't even figure out what is generating the Compilation failed: Cannot run program "java" ... error message.

jmglov08:09:44

Do you have any clue where that could be coming from?

ian08:09:08

is there a reason you have :java-cmd in the project.clj and ~/.lein/profiles.clj?

ian08:09:24

compile.clj seems to generate it

jmglov08:09:50

lein uberjar apparently doesn't use the user profile.

ian08:09:00

no, it uses the uberjar profile

ian08:09:17

oh, I see.

jmglov08:09:52

I suppose I could set an uberjar profile in ~/.lein/profiles.clj, but that's just working around the problem.

jmglov08:09:01

I'd prefer to solve it if I can. simple_smile

ian08:09:25

@jmglov: are you using OracleJDK or OpenJDK or ?

jmglov08:09:34

Oracle JDK.

ian08:09:34

oh, oracle

jmglov08:09:20

It feels like something somewhere is not honouring my PATH.

jmglov08:09:28

Or JAVA_HOME or something.

ian09:09:00

there could be something funny with the lein binary itself maybe? but that wouldn't really make sense..

ian09:09:24

can you lein help or do anything with the lein binary without getting errors?

jmglov09:09:27

I've tried blowing away lein and reinstalling it.

jmglov09:09:41

Let me double-check.

jmglov09:09:20

Yes, that works just fine.

jmglov09:09:56

Sorry, I mean lein help works just fine.

ian09:09:17

yeah I figured

ian09:09:44

unfortunately I'm not sure. 😞 the few other people around the internet that have had this issue seem to just be satisfied with using the :java-cmd method you're using now. I know it would bother me as well, but I'm not smart enough to help you.

jmglov09:09:01

Thanks for trying. simple_smile

jmglov09:09:23

I'll try Stack Overflow, then a GitHub issue.

jmglov11:09:50

@ian: I fixed it, and you aren't going to believe what the issue was!

jmglov11:09:44

In my .bashrc, I had:

export PATH="~/Software/jdk/bin:$PATH"

jmglov11:09:14

When I changed it to this, everything worked:

export PATH="$HOME/Software/jdk/bin:$PATH"

ian19:09:30

@jmglov: I do believe it! I almost asked to see your .bashrc or your $PATH but I didn't think it would've been that deep of an issue. Glad you got it fixed though! Good lesson as well.