简体   繁体   English

如何在Mac OS El Capitan的终端上添加永久的CLASSPATH?

[英]How do I add a permanent CLASSPATH to my Terminal on Mac OS El Capitan?

I want to add the java-servlet-api.jar to the classpath variable. 我想将java-servlet-api.jar添加到classpath变量中。

export CLASSPATH=/.../java-servlet-api.jar

adds the class path to only one session of the terminal. 将类路径仅添加到终端的一个会话。 How do I permanently add this to CLASSPATH? 如何将其永久添加到CLASSPATH?

I looked at a few links which asked me to modify the bashrc file, but I am unable to locate it on EL Capitan. 我查看了一些链接,这些链接要求我修改bashrc文件,但无法在EL Capitan上找到它。 Can someone help me with this? 有人可以帮我弄这个吗?

You choose 1 of 2 solutions below: 您从以下2个解决方案中选择1个:

Solution 1 : Open Terminal, then type: 解决方案1 :打开终端,然后键入:

export CLASSPATH=$CLASSPATH:/path/to/file/java-servlet-api.jar

then: 然后:

source .bash_profile

Solution 2 : Open terminal, type command: 解决方案2 :打开终端,键入命令:

vim ~/.bash_profile

you will see something like this: 您将看到以下内容:

在此处输入图片说明

press i , add your file to classpath like sample. i ,将您的文件添加到classpath,如sa​​mple。

then, press esc , type :wq , then return 然后,按esc ,键入:wq ,然后返回

Make effective: don't need restart, type: 生效:不需要重启,输入:

source .bash_profile

By default, I am not sure that Mac OS terminal launches the .bashrc file. 默认情况下,我不确定Mac OS终端是否启动.bashrc文件。 But it launches the .profile for sure. 但是,它肯定会启动.profile

Open a new terminal and launch this command : 打开一个新终端并启动以下命令:

echo 'export CLASSPATH=/.../java-servlet-api.jar' >> $HOME/.profile

Then open a new terminal and your environment variable should be ok. 然后打开一个新终端,您的环境变量应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM