In order to set my classpath environment variable, I'm running the following command:
export CLASSPATH=/path/to/appropriate/dir
In order to check that this was correctly set, I'll type
echo $CLASSPATH
and am returned /path/to/appropriate/dir.
However, when I open up a new tab or window in the terminal
echo $CLASSPATH
returns nothing. What's going on here?
The variable you set in a terminal, is valid only for that terminal. What you should do is, export the variable in your ~/.bashrc file, which is loaded for each terminal. So, add that statement in the .bashrc file, and you'll be fine.
You can also export the variable from ~/.bash_profile file, which will be loaded for login shells.
for bash, add the following lines to this file (~/.bashrc):
PATH=[your path]:$PATH export PATH
for more details check PATH and CLASSPATH
- Type nano .bashrc 2.Go to the end of line and type ->export CLASSPATH=$CLASSPATH:/usr/share/java/mysql-connector-java.jar(It is the location where you have stored .jar file that you have downloaded). 3.It becomes permanent now
来源:https://stackoverflow.com/questions/21078845/setting-classpath-permanently