Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to specify Java System Properties when running Groovy from command line

Tags:

groovy

Equivalent to java -Dprop="abc" app, but using groovy, like groovy -Dprop="abc" app.groovy

Basically the same question asked here, but negative answers there are relatively old. Anything new support this since 2007?

like image 383
Josh Diehl Avatar asked Nov 11 '11 18:11

Josh Diehl


People also ask

How do I get system properties in Java?

The getProperty(String key) method in Java is used to returns the system property denoted by the specified key passed as its argument.It is a method of the java. lang. System Class. where key is the name of the System property.

How do I set JVM system properties in Windows?

System properties are set on the Java command line using the -Dpropertyname=value syntax. They can also be added at runtime using System. setProperty(String key, String value) or via the various System. getProperties().


1 Answers

Sure; it works as-is:

$ cat sysenv.groovy
println System.getProperty("wat")
$ groovy -Dwat="hello" sysenv.groovy 
hello
like image 105
Dave Newton Avatar answered Sep 27 '22 23:09

Dave Newton