Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy - get JAVA_HOME from program

Tags:

gradle

groovy

I need to obtain JAVA_HOME property from Groovy (Gradle), does anyone know how to achieve this? Only way I can think of is somehow executing this from cmd line via Exec.

Thanks (I'm running Windows btw :))

like image 669
Matthew Lowe Avatar asked Jan 28 '13 15:01

Matthew Lowe


2 Answers

System.properties.find { it.key == "java.home" }
like image 165
Will Avatar answered Sep 27 '22 18:09

Will


A gotcha that bit me. Remember to use curly braces inside a gstring.

println "inside a gstring, java.home=$System.properties.'java.home' will be problematic

//dumps all system properties

but

println "inside a gstring, java.home=${System.properties.'java.home'} will be fine

Result: inside a gstring, java.home=C:\FAST\JDK64\1.7.0.79\jre will be fine

like image 43
James Render Avatar answered Sep 27 '22 16:09

James Render