Environment variables in Eclipse
Solution 1
The .bashrc file is used for setting variables used by interactive login shells. If you want those environment variables available in Eclipse you need to put them in /etc/environment.
Solution 2
You can also define an environment variable that is visible only within Eclipse.
Go to Run -> Run Configurations... and Select tab "Environment".
There you can add several environment variables that will be specific to your application.
Solution 3
I've created an eclipse plugin for this, because I had the same problem. Feel free to download it and contribute to it.
It's still in early development, but it does its job already for me.
https://github.com/JorisAerts/Eclipse-Environment-Variables
Solution 4
You can set the Hadoop home directory by sending a -Dhadoop.home.dir to the VM. To send this parameters to all your application that you execute inside eclipse, you can set them in Window->Preferences->Java->Installed JREs-> (select your JRE installation) -> Edit.. -> (set the value in the "Default VM arguments:" textbox). You can replace ${HADOOP_HOME} with the path to your Hadoop installation.
Solution 5
You can also start eclipse within a shell.
You export the enronment, before calling eclipse.
Example :
#!/bin/bash
export MY_VAR="ADCA"
export PATH="/home/lala/bin;$PATH"
$ECLIPSE_HOME/eclipse -data $YOUR_WORK_SPACE_PATH
Then you can have multiple instances on eclipse with their own custome environment including workspace.
Praveen Sripati
Very passionate about the intersection of Big Data and Cloud technologies. I am a Cloudera Certified Developer for Apache Hadoop, Hortonworks Certified Apache Hadoop Java Developer, AWS Certified Solutions Architect - Associate and AWS Certified Developer - Associate. If interested Consulting/Projects/Trainings around Cloud and Big Data, please contact at [email protected]. Currently I am conducting a training on AWS Development, more details here. I started blogging for fun and started liking it. So, I regularly blog at thecloudavenue.com around Big Data, K8S and Cloud related technologies. I also Tweet here.
Updated on July 05, 2022Comments
-
Praveen Sripati almost 2 years
I am able to run a sample hadoop program from the command prompt and am trying to run the same program from Eclipse, so that I can debug it and understand it better.
For the command line program, some environment variables are set in the
.bashrc
and the same are being read asSystem.getenv().get("HADOOP_MAPRED_HOME")
in the hadoop program. But, when I am running a java program withSystem.getenv().get("HADOOP_MAPRED_HOME")
, from Eclipse I am getting null.I tried passing
-DHADOOP_MAPRED_HOME=test
to VM parameters in the runtime configurations from Eclipse, but still getting null in the standalone program. How to make the environment variables visible within Eclipse? When I iterate throughSystem.getenv()
in Eclipse, I see lot of variables likeDISPLAY
,USER
,HOME
and others. Where are they set? I am using Ubuntu 11.04. -
Praveen Sripati over 12 yearsThanks - it works - just had to reboot the machine - any way to avoid a reboot.
-
Perception over 12 yearsYou can try
source /etc/environment
, but it's not garaunteed to replace environment variables in processes that are already running. Reboot is the safest bet. -
bschandramohan over 11 yearsMax, this is applicable only for the current running Program. If you are running tests or other programs, each of those has to have the environment variable set again.
-
bschandramohan over 11 yearsIs there a equivalent in Mac Os X?
-
Perception over 11 years@ChandraMohan - see here for the best method to set environment variables for Mac OSX apps.
-
Dorrin over 10 yearsThe previous solution did work for me and shows up in getenv() results. The JRE Default VM arguments does not work. I tried on Mac OS X 10.8 using Eclipse Juno.
-
Marcs about 9 yearsIn linux it's enough to restart the greeter (gdm, lxdm, xdm, kdm, etc). Restart the greeter from outside Xorg, open a console (for example using CTRL+ALT+F2), login and restart the greeter service. Then go back to the Xorg session with (CTRL+ALT+F1), can be another F key on your system just try everyone of them.
-
Paddy almost 8 years@Dorrin To access VM arguments, you have to use System.getProperty(). geetenv is for OS level variables.
-
Admin almost 7 yearsYou can do this, but probably shouldn't. It risks the environment variable's value being later changed in the OS or in Eclipse, such that the two end up contradicting each other.
-
gwnp almost 7 yearsThis worked extremely well. I was fighting with a bad install of osx and unable to reinstall at this time but this plugin circumvented the problem.
-
Dag over 6 yearsThis is such a useful plugin, you should do some finishing touch and publish it in the eclipse marketplace.
-
The Student Soul over 6 yearsI was looking for a "global" solution to setting environment variable at one place for all applications running within Eclipse. This helped. +1
-
Stijn de Witt over 6 yearsThis is the best way to do it imho, as it allows you to give each app your are developing on it's own config, instead of having to change your global environment each time.
-
Andrii Karaivanskyi over 6 yearsThank you for the plugin! Works on STS 3.9.1 (Eclipse 4.7.1a)
-
Shui shengbao over 6 yearsVery helpful. I like this way.
-
Karthik about 6 yearsSuper! This really works & removed my long term headache. Thank you!
-
Stewart over 5 yearsBut if you want to run unit tests individually, you have to set this for each test individually, which can become annoying. How does one set that for all run configurations globally?
-
GreenAsJade over 5 yearsTotally agree with other commenters: publish!
-
Don Giusuppe about 5 yearsI've pusblished it: marketplace.eclipse.org/content/…
-
Jerry Zhang over 3 yearsGreat. This is exactly what I want.
-
Jerry Zhang over 3 yearsThere is a bug with Eclipse 4.10. I can install the plugin but could not open environment variables tab. Could you please take a look?
-
demongolem over 3 yearsBut my problem is that environment variables from this tab are not being picked up
-
edvard_munch almost 2 yearsCouldn't find a way to use these variables in external bash script on Ubuntu. The script being called via "Run external tool" button.
JLinkGDBServerCLExe -if swd -speed 4000 -device "1986BE4" -singlerun x-terminal-emulator -e gdb-multiarch -x "$SCRIPT_DIR"
SCRIPT_DIR is picked up on Windows with no problem, being used in external bin filestart JLinkGDBServerCL.exe -if swd -speed 4000 -device "1986BE4" -singlerun start arm-none-eabi-gdb -x "%SCRIPT_DIR%gdbscript.txt%"