如何在Mac OS中为Java配置PATH和CLASSPATH [英] How to configure PATH and CLASSPATH for Java in Mac OS

查看:5073
本文介绍了如何在Mac OS中为Java配置PATH和CLASSPATH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Mac OS上运行Java程序。我为Mac安装了JDK 1.7版,尽管如此,我在执行Java程序时遇到了错误。所以,我知道我必须在Mac中设置PATH和CLASSPATH(环境变量)才能使Java程序成功运行。请帮我解决这个问题。

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.

推荐答案

首先,你需要找到包含所有java二进制文件的bin目录所在的位置。要做到这一点,只需

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

cd /Library/Java/

然后执行一个ls查看此目录中的内容。然后继续cd到内部目录以访问bin文件。它可能与我有点不同,但我的bin目录在这条路径中:

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/

实际上,Home是包含目录的路径名为bin的子目录,其中包含运行java所需的所有java二进制文件。这是需要在PATH环境中定义的路径。
保持这条路径。

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.

其次,我们需要检查是否有.bash_profile。只需cd到家(我的意思是用户目录) - 在任何路径中,如果你只需输入cd并按回车键,你就可以去家里了。
当你在家里时,输入:

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;

和^ O然后输入^ X以保存此文件。

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

如果看到正确的版本java正在出现 - 成功!

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

引用:
http://www.sajeconsultants.com/how-to-set-java_home-on-mac-os-x/

这篇关于如何在Mac OS中为Java配置PATH和CLASSPATH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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