View and set Java_home under Mac OS X

Source: Internet
Author: User
Tags java se



Original link: http://blog.csdn.net/done58/article/details/51138057






1. View Java version



Open your Mac computer, view the Java version, open Terminal Terminal, and view the author's Java version from the command line:


[HTML]View PlainCopy
    1. bogon:~ donny$ java-version
    2. Java Version "1.7.0_71"
    3. Java (TM) SE Runtime Environment (build 1.7.0_71-b14)
    4. Java HotSpot (TM) 64-bit Server VM (build 24.71-b01, Mixed mode)


Discover that the Java Runtime environment is installed. If your system already has a successful JDK installed, you can see the corresponding JDK version via java-version. If your computer does not have a JDK installed, you can download the JDK on the Oracle website.






2. View the Java installation path





[HTML]View PlainCopy
    1. bogon:~ donny$ which Java
    2. /usr/bin/java
    3. bogon:~ donny$ Whereis Java
    4. /usr/bin/java
    5. bogon:~ donny$


Through Ls-l/usr/bin/java can't find the real installation path, discovered this article by searching 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& Nbsp;command line tool on Mac OS X 10.5 or later. On older Mac OS X versions where the tool is does not exist and 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 the 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 PLATF ORM version when locating a $JAVA _home.



Another advantage of dynamically finding this path, as opposed to hardcoding the fixed endpoint, was that it is updated whe n a new version of Java is downloaded via software Update or installed with a newer version of Mac OS x. For this reason, it's important that developers does not install files/Systemin the JDKs inside of, since the changes would Be lost with subsequent updates by newer versions of Java.



To obtain the path to the currently executing$JAVA_HOME, use thejava.homeSystem property.





[HTML]View PlainCopy
    1. bogon:~ donny$ ls-l/usr/libexec/java_home
    2. Lrwxr-xr-x 1 root Wheel 1 15:43/usr/libexec/java_home->/system/library/frameworks/javavm.framework/ve Rsions/current/commands/java_home





This is still not in the real position. According to the Internet search Mac OSX 10.9 system comes with the Java 6 environment, the path in:



The/library/java/javavirtualmachines folder. What does the result of this path look like?





[HTML]View PlainCopy
    1. Bogon:home donny$ Cd/library/java/javavirtualmachines
    2. Bogon:javavirtualmachines donny$ ls
    3. Jdk1.7.0_71.jdk





You can see the real jdk here, and the final path is:





[HTML]View PlainCopy
    1. /library/java/javavirtualmachines/jdk1.7.0_71.jdk/contents/home





You can refer to the Apple file document description, after the command/usr/libexec/java_home use the-V option to list all versions of Java_home, that is, the following results:





[HTML]View PlainCopy
    1. Bogon:home donny$/usr/libexec/java_home-v
    2. Matching Java Virtual Machines (1):
    3. 1.7.0_71, x86_64: "Java SE 7"/library/java/javavirtualmachines/jdk1.7.0_71.jdk/contents/home
    4. /library/java/javavirtualmachines/jdk1.7.0_71.jdk/contents/home





3, set java_home environment variable



CD back to the user directory, and then list all the current files, you can see the current system. Start all files.





[HTML]View PlainCopy
    1. Bogon:home donny$ CD
    2. bogon:~ donny$ ls-a


Add Java_home to the. bash_profile file






Export java_home=$ (/usr/libexec/java_home)
Export path= $JAVA _home/bin: $PATH
Export class_path= $JAVA _home/lib need to note that after Mac OSX 10.5, Apple is recommended to set the $java_home variable to/usr/libexec/java_home, after adding, press ESC to exit the insert mode, and type wq! to save the exit file.



In this step, we have configured the global Java path and CLASSPATH environment variables. In the future, Java development will be good.



View and set Java_home under Mac OS X


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.