Environment variables in Eclipse

234,736

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".

enter image description here

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

enter image description here

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.

Select the JRE you use for running programs in Eclipse

Sending the value for hadoop.home.dir property as a VM argument

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.

Share:
234,736
Praveen Sripati
Author by

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, 2022

Comments

  • Praveen Sripati
    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 as System.getenv().get("HADOOP_MAPRED_HOME") in the hadoop program. But, when I am running a java program with System.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 through System.getenv() in Eclipse, I see lot of variables like DISPLAY, USER, HOME and others. Where are they set? I am using Ubuntu 11.04.

  • Praveen Sripati
    Praveen Sripati over 12 years
    Thanks - it works - just had to reboot the machine - any way to avoid a reboot.
  • Perception
    Perception over 12 years
    You 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
    bschandramohan over 11 years
    Max, 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
    bschandramohan over 11 years
    Is there a equivalent in Mac Os X?
  • Perception
    Perception over 11 years
    @ChandraMohan - see here for the best method to set environment variables for Mac OSX apps.
  • Dorrin
    Dorrin over 10 years
    The 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
    Marcs about 9 years
    In 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
    Paddy almost 8 years
    @Dorrin To access VM arguments, you have to use System.getProperty(). geetenv is for OS level variables.
  • Admin
    Admin almost 7 years
    You 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
    gwnp almost 7 years
    This 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
    Dag over 6 years
    This is such a useful plugin, you should do some finishing touch and publish it in the eclipse marketplace.
  • The Student Soul
    The Student Soul over 6 years
    I 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
    Stijn de Witt over 6 years
    This 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
    Andrii Karaivanskyi over 6 years
    Thank you for the plugin! Works on STS 3.9.1 (Eclipse 4.7.1a)
  • Shui shengbao
    Shui shengbao over 6 years
    Very helpful. I like this way.
  • Karthik
    Karthik about 6 years
    Super! This really works & removed my long term headache. Thank you!
  • Stewart
    Stewart over 5 years
    But 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
    GreenAsJade over 5 years
    Totally agree with other commenters: publish!
  • Don Giusuppe
    Don Giusuppe about 5 years
  • Jerry Zhang
    Jerry Zhang over 3 years
    Great. This is exactly what I want.
  • Jerry Zhang
    Jerry Zhang over 3 years
    There 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
    demongolem over 3 years
    But my problem is that environment variables from this tab are not being picked up
  • edvard_munch
    edvard_munch almost 2 years
    Couldn'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 file start JLinkGDBServerCL.exe -if swd -speed 4000 -device "1986BE4" -singlerun start arm-none-eabi-gdb -x "%SCRIPT_DIR%gdbscript.txt%"