Reputation: 11377
Gradle provides a handy application
plugin which you can use like this
apply plugin: 'application'
mainClassName = "foo.bar.Baz"
then invoke "*dist" tasks and get some scripts generated to run the app
bin/
app
app.bat
lib/
...
however when i run sh app -DmyConfig=myValue
the application won't get a jvm argument by name myConfig.
So how do we pass arguments trough command line?
Upvotes: 4
Views: 1666
Reputation: 38639
All parameters you give the default launch script generated by Gradle are passed on like they are to the main method of your program, but there are some environment variables you can set, or you can do the setting in your main method.
So either you parse your args in main
and set the system properties from your code, or you set environment variables. The default Gradle-generated launcher scripts consider three environment variables that it adds together. DEFAULT_JVM_OPTS
which is set within the launcher script, JAVA_OPTS
which is meant for all Java programs that respect this property and one additional environment property that is specific to your program. Just look inside the launcher script to find out its name.
As third option you can of course also use an own launcher script that does special handling of parameters that start with -D and sets them as system properties instead of giving them to your programs main
method.
As your question suggests that you are working in a linux shell, one way to set an environment variable just for one call of an app would be YOUR_APP_OPTS="-DyourProp=yourVal" ./yourApp
. But any way to set an environment variable would be fine.
Upvotes: 5