Mac OS X 下查看和设置JAVA_HOME
2016-04-12 23:19
429 查看
1, 查看JAVA版本
打开Mac电脑,查看JAVA版本,打开终端Terminal,通过命令行查看笔者的java版本::
2, 查看JAVA安装路径
Many Java applications need to know the location of a
Mac OS X should be found using the
exist, use the fixed path "
dynamically finds the top Java version specified in Java Preferences for the current user. This path allows access to the
line tools such as
platforms. The tool
Another advantage of dynamically finding this path, as opposed to hardcoding the fixed endpoint, is that it is updated when a new version of Java is downloaded via Software Update or installed with a newer version of Mac OS X. For this reason, it is important
that developers do not install files in the JDKs inside of
To obtain the path to the currently executing
property.
这还是没定位到真实的位置。根据网上搜索Mac OSX 10.9以后系统就自带了Java 6的环境,路径在:
/Library/Java/JavaVirtualMachines文件夹下。下面看这个路径的结果是什么样?
可以看到真实的JDK在这里了,最终的路径是:
可以参照苹果的文件文档说明,在命令 /usr/libexec/java_home 后面使用-V选项列出所有版本的JAVA_HOME,即如下的结果:
3, 设置JAVA_HOME环境变量
cd回到用户目录,再列出当前的所有文件,可以见到当前系统的.开头的所有文件。
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
export CLASS_PATH=$JAVA_HOME/lib 需要说明的是Mac OSX 10.5之后苹果就建议设置$JAVA_HOME变量到/usr/libexec/java_home,添加完毕之后,按esc退出插入模式,并键入wq!保存退出文件。
到这个步骤,我们就已经配置好了全局的java的path和classpath环境变量。以后就可以好好的进行java开发了。
打开Mac电脑,查看JAVA版本,打开终端Terminal,通过命令行查看笔者的java版本::
bogon:~ donny$ java -version java version "1.7.0_71" Java(TM) SE Runtime Environment (build 1.7.0_71-b14) Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)发现已安装Java运行环境。如果你的系统已经安装成功JDK,通过java -version就可以看到相应的jdk版本。如果你的电脑还没有安装JDK的话,可以到Oracle官网下载jdk。
2, 查看JAVA安装路径
bogon:~ donny$ which java /usr/bin/java bogon:~ donny$ whereis java /usr/bin/java bogon:~ donny$通过ls -l /usr/bin/java 不能找到真实的安装路径,通过搜索发现了这篇文章Important Java Directories on Mac OS X, https://developer.apple.com/library/mac/qa/qa1170/_index.html。
Many Java applications need to know the location of a
$JAVA_HOMEdirectory. The
$JAVA_HOMEon
Mac OS X should be found using the
/usr/libexec/java_homecommand line tool on Mac OS X 10.5 or later. On older Mac OS X versions where the tool does not
exist, use the fixed path "
/Library/Java/Home". The
/usr/libexec/java_hometool
dynamically finds the top Java version specified in Java Preferences for the current user. This path allows access to the
binsubdirectory where command
line tools such as
java,
javac, etc. exist as on other
platforms. The tool
/usr/libexec/java_homeallows you to specify a particular CPU architecture and Java platform version when locating a
$JAVA_HOME.
Another advantage of dynamically finding this path, as opposed to hardcoding the fixed endpoint, is that it is updated when a new version of Java is downloaded via Software Update or installed with a newer version of Mac OS X. For this reason, it is important
that developers do not install files in the JDKs inside of
/System, since the changes will be lost with subsequent updates by newer versions of Java.
To obtain the path to the currently executing
$JAVA_HOME, use the
java.homeSystem
property.
bogon:~ donny$ ls -l /usr/libexec/java_home lrwxr-xr-x 1 root wheel 79 Nov 1 15:43 /usr/libexec/java_home -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home
这还是没定位到真实的位置。根据网上搜索Mac OSX 10.9以后系统就自带了Java 6的环境,路径在:
/Library/Java/JavaVirtualMachines文件夹下。下面看这个路径的结果是什么样?
bogon:Home donny$ cd /Library/Java/JavaVirtualMachines bogon:JavaVirtualMachines donny$ ls jdk1.7.0_71.jdk
可以看到真实的JDK在这里了,最终的路径是:
/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
可以参照苹果的文件文档说明,在命令 /usr/libexec/java_home 后面使用-V选项列出所有版本的JAVA_HOME,即如下的结果:
bogon:Home donny$ /usr/libexec/java_home -V Matching Java Virtual Machines (1): 1.7.0_71, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
3, 设置JAVA_HOME环境变量
cd回到用户目录,再列出当前的所有文件,可以见到当前系统的.开头的所有文件。
bogon:Home donny$ cd bogon:~ donny$ ls -a添加java_home到.bash_profile文件中
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH
export CLASS_PATH=$JAVA_HOME/lib 需要说明的是Mac OSX 10.5之后苹果就建议设置$JAVA_HOME变量到/usr/libexec/java_home,添加完毕之后,按esc退出插入模式,并键入wq!保存退出文件。
到这个步骤,我们就已经配置好了全局的java的path和classpath环境变量。以后就可以好好的进行java开发了。
相关文章推荐
- MySql数据类型和Java数据类型对应一览
- Java示例
- 20145229吴姗珊 《Java程序设计》两天小总结
- Java实现八数码问题
- 牛客网-华为机试在线训练-2.取近似值
- Eclipse使用总结
- 编写程序,将指定目录下所有.java 文件拷贝到另一个目的中,并将扩展名改为.txt。
- Spring中bean的scope
- Maven配置Spring+SpringMVC+MyBatis(3.2.2)Pom
- Java I/O(一) NIO概述
- Intellijidea建javaWeb以及Servlet简单实现
- myeclipse与mysql练习
- java OPENCV 连通域, Imgproc.findContours 例子,参数说明
- struts2标签在jsp不显示问题(不经过action跳转)
- JAVA多线程学习(一)
- java字节码中的aload_0
- LeetCode Merge Sorted Array 88
- Java枚举类
- Hibernate映射集合(JDK以及嵌入式值类)
- Java获取 JVM 运行信息