Hi Gary,

System.getEnv() will return O/S environment variables.
E.g. System.out.println("Path: " + System.getenv("PATH")); would print my
current PATH variable.

System.getProperty() is what you are thinking of.  E.g. adding -Denv=dev to
my VM options in Netbeans, then calling System.out.println("Environment: "
+ System.getProperty("env")); will print:

Environment: dev


Hope that helps,

P

On Thu, Oct 8, 2020 at 4:34 AM Greenberg, Gary <ggree...@visa.com.invalid>
wrote:

> I have created a Java application for some data conversion.
>
> It accepts 2 parameters in the command line: input and output file.
>
> Besides that, some program options are defined by the properties file.
>
> I have several of these properties files for different environments, where
> name of the environment included as a suffix of the properties file name.
>
> The environment name I planned to pass as –Denv=value
>
> Now I am trying to run/debug my application from the Netbeans.
>
> First, I specified input and output file in the arguments window of the
> project properties and –Denv=dev in the VM options window.
>
> In this case System.getenv(“env”) returned null. I.e. environment variable
> was not set.
>
> Then, I tried to move this setting from VM options to attributes and
> program failed with the following stack trace:
>
> Command execution failed.
>
> org.apache.commons.exec.ExecuteException: Process exited with an error: 1
> (Exit value: 1)
>
>     at org.apache.commons.exec.DefaultExecutor.executeInternal
> (DefaultExecutor.java:404)
>
>     at org.apache.commons.exec.DefaultExecutor.execute
> (DefaultExecutor.java:166)
>
>     at org.codehaus.mojo.exec.ExecMojo.executeCommandLine
> (ExecMojo.java:764)
>
>     at org.codehaus.mojo.exec.ExecMojo.executeCommandLine
> (ExecMojo.java:711)
>
>     at org.codehaus.mojo.exec.ExecMojo.execute (ExecMojo.java:289)
>
>     at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo
> (DefaultBuildPluginManager.java:137)
>
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute
> (MojoExecutor.java:210)
>
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute
> (MojoExecutor.java:156)
>
>     at org.apache.maven.lifecycle.internal.MojoExecutor.execute
> (MojoExecutor.java:148)
>
>     at
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject
> (LifecycleModuleBuilder.java:117)
>
>     at
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject
> (LifecycleModuleBuilder.java:81)
>
>     at
> org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build
> (SingleThreadedBuilder.java:56)
>
>     at org.apache.maven.lifecycle.internal.LifecycleStarter.execute
> (LifecycleStarter.java:128)
>
>     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
>
>     at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
>
>     at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
>
>     at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
>
>     at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
>
>     at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
>
>     at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
>
>     at sun.reflect.NativeMethodAccessorImpl.invoke
> (NativeMethodAccessorImpl.java:62)
>
>     at sun.reflect.DelegatingMethodAccessorImpl.invoke
> (DelegatingMethodAccessorImpl.java:43)
>
>     at java.lang.reflect.Method.invoke (Method.java:498)
>
>     at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced
> (Launcher.java:282)
>
>     at org.codehaus.plexus.classworlds.launcher.Launcher.launch
> (Launcher.java:225)
>
>     at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode
> (Launcher.java:406)
>
>     at org.codehaus.plexus.classworlds.launcher.Launcher.main
> (Launcher.java:347)
>
>
>
> Can anyone tells me what is the right way to specify this environment
> variable?
>
> Thanks,
>
> Gary Greenberg
>
> Staff Software Engineer
>
> Data Product Development, BI-A
>
> E: ggree...@visa.com
>
> M: 650-269-7902
>
>
>
> [image: EmailSig-TaglineVersion]
>
>
>

Reply via email to