开发者

global variable but still can't access in linux

开发者 https://www.devze.com 2023-01-18 16:58 出处:网络
i have trying to use some global variable in my ant file. when i do login through terminal. i can access those variable like JAVA_HOME

i have trying to use some global variable in my ant file. when i do login through terminal. i can access those variable like JAVA_HOME but when i am trying to access variable through the ant command i am not able to find them. global variable declared in .cshrc

setenv JAVA_HOME jdk_full_path

ant code using variable.

<property environment="env"/>
<property name="ear" value= "true"/>
<property name="home" value="${env.HOME}"/>
<property name="开发者_Python百科java_home" value="${env.JAVA_HOME}"/>

i can access home variable but i am not able to find JAVA_HOME variable ,i am executing this ant through eclipse

Please suggest me where should i declare the variable so i can access them


The problem is probably that Eclipse doesn't have JAVA_HOME in its environment.

Try logging out and back in again, then run Eclipse.

Alternatively, open a terminal, and run Eclipse from there.


The .cshrc file is only run when you start a new C shell, it is not for global variables. Since you are not starting Eclipse from the C shell it will not see any variables you set there.

Try the ~/.login file or the /etc/profile file in case eclipse starts up using bash. Both of these files are only loaded once when the user logs on so they should effect everything. You may require a restart or even a reboot for changes to these files to take effect.


Environment variables are inherited through process execution, they are not global. So, when you edit your shell's RC file to add a variable, it only takes effect for shells executed AFTER that modification, and for programs executed from those shells. If you started Eclipse from KDE/Gnome, and KDE/Gnome was started before you made that change, then KDE/Gnome never had the definition and therefore Eclipse did not either.

I recommend logging out and back in. Also, depending on your default shell setting, you may find that KDE/Gnome is being started through bash or something else, meaning that you'll need to modify .bashrc instead of .cshrc.


You should define this variables at one of the following files:

~/.profile or ~/.bash_profile runs only with login shells i.e when you first log in into system.

~/.bashrc file runs every time you open a new non-login bash shell such as xterm

So, you should add to this files the line:

export JAVA_HOME=jdk_full_path

You must re-login for the changes take efect

0

精彩评论

暂无评论...
验证码 换一张
取 消