Why does Java use SYSTEM.GETENV () to get the environment variable you just set is empty

Source: Internet
Author: User

Scene:

Eclipse has been launched under Ubuntu, and the environment variable (export $ENV =123) has been set through the terminal and then displayed as empty when obtained through SYSTEM.GETENV ().

Explain:

Environment variables are only under the process tree and only when the process is started. Eclipse is a child of your shell-so when you start eclipse, it inherits all of the environment variables defined on your shell.

You might have defined environment variables on the shell after you started eclipse, so Eclipse and the Java child processes it created are not aware of your new environment variables.

Because of this behavior, the solution here is actually to exit Eclipse and restart it from the shell, which is defined before the environment variable. Another option is to go to the project's run configuration and define the environment variables in it.

Reference:

Https://stackoverflow.com/questions/29782467/system-getenv-returns-null-when-the-environment-variable-exists

Why does Java use SYSTEM.GETENV () to get the environment variable you just set is empty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.