You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by "Greenberg, Gary" <gg...@visa.com.INVALID> on 2020/10/08 03:34:10 UTC
Recognizing environment variable while running java app in NB 12.0
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: ggreenbe@visa.com
M: 650-269-7902
[EmailSig-TaglineVersion]
Re: Recognizing environment variable while running java app in NB 12.0
Posted by Som Lima <so...@gmail.com>.
You can access environment variables using the brace-enclosed environment
variable syntax. Example:
VM options: -Dfoo=${MY_ENV_VAR}
https://stackoverflow.com/questions/21558855/using-environment-variables-in-vm-options-and-program-arguments
On Thu, 8 Oct 2020, 04:34 Greenberg, Gary, <gg...@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: ggreenbe@visa.com
>
> M: 650-269-7902
>
>
>
> [image: EmailSig-TaglineVersion]
>
>
>
Re: Recognizing environment variable while running java app in NB 12.0
Posted by Pete Whelpton <pe...@gmail.com>.
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 <gg...@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: ggreenbe@visa.com
>
> M: 650-269-7902
>
>
>
> [image: EmailSig-TaglineVersion]
>
>
>