In my Groovy script I have this code:
def username = System.getenv()['USER'] def password = System.getenv()['PASS']
It is because I can't use this information as parameter to Groovy script, because other users shouldn't know it. When I run this script I set this parameter in my system. Now I have a problem. I have a Java application which runs Groovy script remotely. Is there some way that I can set enviromental variable in Java code? (Aquí I found that it isn't possible). Or is there some safe ways to send this properties from Java to Groovy?
preguntado el 31 de julio de 12 a las 11:07
If you're launching the groovy script by the lowest common denominator of
Runtime.exec (or similar), then you can specify the environment in one of the overloaded methods:
Executes the specified string command in a separate process with the specified environment.
envp- array of strings, each element of which has environment variable settings in the format name=value, or null if the subprocess should inherit the environment of the current process.
If on the other hand you're invoking the Groovy script within the same Java process, then it will have the same properties as the running process. So simply calling
System.setProperty("USER", xxx) before invoking the Groovy script will mean this property is visible to your Groovy logic.
Debe tener en cuenta que el entorno is an operating-system level thing; a measure of the properties of the OS on which the process is running.
If you're looking for application-level settings, you really ought to be checking