Java类路径-Linux [英] Java classpath - Linux

查看:103
本文介绍了Java类路径-Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解classpath的真正工作原理.在网上搜索后,到目前为止,这是我到达的地方:

I am trying to understand how classpath really works. After searching around the web this is where I have reached so far:

我已添加

export CLASSPATH="/home/foo:/home/foo/Java_code/my_code"

/etc/environment.顺便说一下,我正在运行Ubuntu.

at /etc/environment. I am running Ubuntu by the way.

Java找到路径并编译没有问题.

Java finds the path and compiles without problem.

问题是,如果我更改CLASSPATH,然后执行以下操作:source /etc/environment,则不会应用新的CLASSPATH.当且仅当我重新启动系统时,它才适用.例如,如果我删除

The problem is that if I change the CLASSPATH and then I do: source /etc/environment, the new CLASSPATH is not applied. It is applied if and only if I restart the system. For example if I delete the

export CLASSPATH="/home/foo:/home/foo/Java_code/my_code"

行,然后我执行/etc/environment的源代码,最后我执行echo $CLASSPATH,得到的是/home/foo:/home/foo/Java_code/my_code.我想我应该留空行,不是吗?

line, then I do source /etc/environment and I finally do echo $CLASSPATH, what I get is /home/foo:/home/foo/Java_code/my_code. I think I should get an empty line, shouldn't I?

是否有一种方法可以立即应用PATH或CLASSPATH变量中的更改而无需重新启动系统?

Is there a way to apply the changes in PATH or CLASSPATH variables immediately without having to restart the system?

这可能会帮助您了解/etc/environment文件最初仅包含以下行:

It might help you know that the /etc/environment file originally contained only the following line:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

谢谢您的时间.

推荐答案

我认为您不应在系统范围的文件中放置主目录本地的任何路径.除非您提供一些对所有用户都是必要或有益的更改,否则我将不理会/etc/environment. 将对CLASSPATH的所有更改放在主目录的.bashrc中.

I think you should not put any paths that a local to your home directory in a system wide file. I would leave /etc/environment well alone, unless you provide some changes, that are necessary or beneficial to all users. Put any changes to the CLASSPATH in your .bashrc in your home directory.

  CLASSPATH=$CLASSPATH:/home/foo:/home/foo/Java_code/my_code
  export CLASSPATH

通过这种方式可以获取它,并且任何新近启动的bash都将立即具有设置.

This way you can source it and any newly started bash will have the settings right at once.

这篇关于Java类路径-Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆