mac java classpath,如何在Mac OS中为Java配置PATH和CLASSPATH

I am trying to run Java programs on Mac OS. I installed JDK version 1.7 for Mac and even though, I am getting errors in executing Java program. So, I got to know that I have to set PATH and CLASSPATH (Environment variables) in Mac to get the Java programs run successfully. Please help me with the issue.

解决方案

First, you need to find where the bin directory that contains all java binary files is located. To do that simply

cd /Library/Java/

Then do one "ls" to see what you have in this directory. Then continue cd to the inner directories to reach to the bin file. It might be a little different from me but my bin directory is in this path:

/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/

In fact, Home is the path of the directory that contains the subdirectory named "bin" which contains all the java binary files needed for running java. This is the path that needs to be defined in PATH environment.

keep this path.

Second, we need to check whether we have the.bash_profile or not. Simply cd to the home (I mean the user directory) -- in any path if you just type cd and press enter, you can go to the home.

When you are located in home, type this:

cat .bash_profile

if you see the error regarding a problem in finding the file then you need to create this file. For creating this file type this:

nano .bash_profile

you can see that the editor for writing into this file is open now. Then simply write this:

JAVA_HOME= /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/

export JAVA_HOME;

and ^O then enter then ^X to save this file.

Third, exit the terminal and reopen it and for testing whether you set the path environment or not write this comment in the terminal:

$JAVA_HOME/bin/java -version

If you see the correct version of java is showing up --Success!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值