Skip to content

Instantly share code, notes, and snippets.

@camsaul
Created March 29, 2017 18:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save camsaul/c982019fd915510677236cd4b720a583 to your computer and use it in GitHub Desktop.
Save camsaul/c982019fd915510677236cd4b720a583 to your computer and use it in GitHub Desktop.
Run lein with different JVM
#!/bin/bash
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home lein run
@camsaul
Copy link
Author

camsaul commented Mar 29, 2017

Also set permanently in ~/.lein/profiles.clj:

{:user {:java-cmd "/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java"}}

@camsaul
Copy link
Author

camsaul commented Mar 29, 2017

@camsaul
Copy link
Author

camsaul commented Apr 26, 2017

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home \
JAVA_TOOL_OPTIONS='-XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:MaxPermSize=256m' \
lein run

@camsaul
Copy link
Author

camsaul commented Apr 26, 2017

@camsaul
Copy link
Author

camsaul commented Apr 26, 2017

Actually apparently OpenJDK is already included here:

 /Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/MacOS/itms/java/bin/java

So:

JAVA_HOME='/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/MacOS/itms/java' \
JAVA_TOOL_OPTIONS='-XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:MaxPermSize=256m' \
lein run

@camsaul
Copy link
Author

camsaul commented Dec 18, 2017

lein version to double-check JAVA_HOME worked correctly

@camsaul
Copy link
Author

camsaul commented Jan 5, 2018

Use Java 8:

JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home lein run

# to run things like JARs
alias java=$JAVA_HOME/bin/java

@jprudent
Copy link

jprudent commented Sep 2, 2020

Note : I couldn't use JAVA_HOME, had to use JAVA_CMD

JAVA_CMD=/home/jerome/bin/jdk1.8.0_131/bin/java lein -v
Leiningen 2.9.1 on Java 1.8.0_131 Java HotSpot(TM) 64-Bit Server VM

@camsaul
Copy link
Author

camsaul commented Sep 25, 2020

@jprudent I've been using Jabba (https://github.com/shyiko/jabba) for this stuff now

@leifericf
Copy link

leifericf commented Jan 2, 2022

Is it possible to set JVM version per project, for example via project.clj?

Edit: I discovered how to do this with jEnv, using jenv local <jvm-version> within my project directory. I suppose that does the trick! Although it would still be useful to do this in project.clj, add to source control, etc.

@mourginakis
Copy link

mourginakis commented Sep 15, 2022

Is it possible to set JVM version per project, for example via project.clj?

you can, add
:java-cmd "/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java"
to your project.clj, or the path of whatever other java binary you are using

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