31

I am running maven based Spring project in netbeans . I am using an environment variable in my project configurations file to Open specific file based on that variable value . I am able to set it In Eclipse but do not know how to set in Netbeans . Can any one help me?

Rohit Kumar
  • 1,018
  • 3
  • 12
  • 23
  • possible duplicate of [How do I set up a java environment variable in Netbeans](http://stackoverflow.com/questions/8577249/how-do-i-set-up-a-java-environment-variable-in-netbeans) –  Aug 06 '12 at 09:28
  • http://stackoverflow.com/questions/8577249/how-do-i-set-up-a-java-environment-variable-in-netbeans is not a duplicate because it's about system properties and not environment variables (the title said it the other way around, edit already suggested) – Kalle Richter Jan 22 '17 at 01:29

3 Answers3

49
System.getEnv("FOO") == "FOOVALUE"

netbeans 6.7+ -

Right click Project

  • ->Properties ->Actions ->Run project ->Set Properties: Add

Env.FOO=FOOVALUE

Note: You can apply the same technique on other configurations and other actions like Debug project

sureshnath
  • 506
  • 6
  • 3
3

I could not find that Properties->Actions setting, using NetBeans 7.4. I did not explicitly need an environment variable--just some value I could set outside my application. So, instead, I was able to make a change in the "project.properties" file under the nbproject folder of the main application.

Within project.properties is a "run.args.extra" setting. Any command line argument you wish to pass along must have its 'name' preceded by '-J'. Here is an example.

run.args.extra=-J-DFOO=FOOVALUE

Note that this is NOT an environment variable. Rather, it is a System.getProperty("FOO") accessible value. Of special note: this is also the place to change how much memory your applications allocate, using Xmx/Xms.

Javaneer
  • 41
  • 5
2

On macOS:

In $HOME/.bashrc add alias:

alias netbeans='/Applications/NetBeans/NetBeans\ X.Y.app/Contents/MacOS/netbeans &'

In Terminal:

> netbeans

This will start IDE with user environment variables.

As result environment variables (such as $PATH) available inside NetBeans IDE and tools (such as Ruby debugger).

Vlad
  • 6,402
  • 1
  • 60
  • 74