標籤:mode 結果 war osx current https download 文檔 virtual
原文連結 : http://blog.csdn.net/done58/article/details/51138057
1, 查看Java版本
開啟Mac電腦,查看JAVA版本,開啟終端Terminal,通過命令列查看筆者的java版本::
[html] view plain copy
- 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安裝路徑
[html] view plain copy
- 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_HOME
directory. The $JAVA_HOME
on Mac OS X should be found using the /usr/libexec/java_home
command 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_home
tool dynamically finds the top java version specified in Java Preferences for the current user. This path allows access to the bin
subdirectory where command line tools such as java
, javac
, etc. exist as on other platforms. The tool /usr/libexec/java_home
allows 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.home
System property.
[html] view plain copy
- 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檔案夾下。下面看這個路徑的結果是什麼樣?
[html] view plain copy
- bogon:Home donny$ cd /Library/Java/JavaVirtualMachines
- bogon:JavaVirtualMachines donny$ ls
- jdk1.7.0_71.jdk
可以看到真實的JDK在這裡了,最終的路徑是:
[html] view plain copy
- /Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
可以參照蘋果的檔案文檔說明,在命令 /usr/libexec/java_home 後面使用-V選項列出所有版本的JAVA_HOME,即如下的結果:
[html] view plain copy
- 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回到使用者目錄,再列出當前的所有檔案,可以見到當前系統的.開頭的所有檔案。
[html] view plain copy
- 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開發了。
Mac OS X 下查看和設定JAVA_HOME