Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8523485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:25:21+00:00 2026-06-11T07:25:21+00:00

Everywhere I search, it says you can get an environment variable by using System.getenv(str).

  • 0

Everywhere I search, it says you can get an environment variable by using System.getenv(str).

It’s not working for me. Here’s what I am doing:
OS : Mac OS x 10.7
Java 1.6.x

If I do export abc=/hello/ in my terminal and then echo $abc, it gives me the variable. If I close the terminal, reopen it again and do echo $abc, it’s gone. To overcome this, I edited my .bash_profile file and inserted export abc=/hello/. Close the terminal, do echo $abc and it works. So I understood that the env variable is permanent now.

Now if in my java console app, I print System.getenv("abc"), it returns null. What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:25:23+00:00Added an answer on June 11, 2026 at 7:25 am

    The reason that you needed to put the export in your .bash_profile is that setting environment variables in a shell only persist the variables in that shell, and – since you used export – to children of that shell, or in other words, other programs launched by that shell.

    If you’re running your java code from Eclipse, and you launch Eclipse from a shell with your environment variables set, then your program should see the added environment variables. To launch Eclipse from the shell, you’ll need to use the OS X open command:

    $ open /Applications/eclipse/Eclipse.app
    

    Alternately, you can set the environment variables within your Eclipse project, and you’ll need to do this if you’re not launching Eclipse from a shell with the proper environment. In the Run Configurations dialog, look for a tab named Environment. Here you’ll find a table for adding environment variables that will be passed to your program.

    It’s better to add the environment variables to the Run Configuration since that way they’ll always be available to your project. Your code doesn’t actually care where the environment variables are coming from, and adding them to the project is simpler, and will work the same way on different platforms.

    Of course, when you run your program outside Eclipse, you’ll need to make sure that the same environment variables exist in the shell where you e.g. run java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you get the directory target of a shortcut folder? I've search everywhere
I've search everywhere for a pointer to this, but can't find one. Basically, I
I'm very new to DLL objects and I search everywhere and can't find the
I have a problem here. I've tried searching everywhere but can't seems to find
I looked at in everywhere and couldn't find it, or my search was not
I search everywhere and tried everything I could, but I cannot make my second
Everywhere I see, can't find any info about it. I need that people who
I've been looking everywhere but I'm either blind or it's really not there. I'm
I have been looking everywhere but could not find a tutorial for this. I
It seems everywhere I read that either a library boasts if not needing RTTI

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.