Java On MacOS

About

  • JDK: Java development toolkit, the library of Java, using to complie and run Java programs
  • J2EE: Java 2 enterprise edition, for enterprise
  • J2SE: Java 2 standard edition, standar version
  • J2ME: Java 2 Micro Edition, usually for mobile developement

Install JDK

If you use Eclipse, you don’t have to install Java development, it has one.

Download JDK

Download JDK from https://www.oracle.com/technetwork/java/javase/downloads/jdk11-downloads-5066655.html

I use jdk-11.0.2_osx-x64_bin.dmg

Installation

After install the dmg file, enter java -version in terminal to test whether it is successful:

1
2
3
4
$ java -version
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)

Enviroment

Add PATH and CALSSPATH

Check the version:

1
2
$ ls /Library/Java/JavaVirtualMachines/
jdk-11.0.2.jdk

Or open Finder, press “Command + Shift + G”, and enter /Library/Java/JavaVirtualMachines/ to see it.

Edit profile:

1
$ sudo vim /etc/profile

Add this at the last:

1
2
3
4
5
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/"
CLASS_PATH="$JAVA_HOME/lib"
PATH=".:$PATH:$JAVA_HOME/bin

The whole file should be like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# System-wide .profile for sh(1)
if [ -x /usr/libexec/path_helper ]; then
eval `/usr/libexec/path_helper -s`
fi
if [ "${BASH-no}" != "no" ]; then
[ -r /etc/bashrc ] && . /etc/bashrc
fi
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/"
CLASS_PATH="$JAVA_HOME/lib"
PATH=".:$PATH:$JAVA_HOME/bin"

Press esc and enter :wq! to sava and exit.

Enter this to make it effective:

1
$ source /etc/profile

Test

Write a Hello.jav file.

1
2
3
4
5
class Hello {
public static void main(String[] args) {
System.out.println("Hello Laker");
}
}

Compile it :

1
2
# laker @ Laker in ~/Downloads [21:23:40] C:1
$ javac Hello.java

Run it

1
2
3
# laker @ Laker in ~/Downloads [21:24:12]
$ java Hello
Hello Laker

Uninstallation

Futhermore, the uninstallation is following command:
https://blog.csdn.net/qq_30889373/article/details/78863313

  • Fisrt
1
2
$ sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
$ sudo rm -fr /Library/PreferencesPanes/JavaControlPanel.prefpane
  • Second

Check the version:

1
2
$ ls /Library/Java/JavaVirtualMachines/
jdk-11.0.2.jdk

Remove

1
$ sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk

Exchange blogroll: http://laker.me/blog
Github:https://github.com/younglaker


Java On MacOS

本文原创自http://laker.me/blog,转载请注明出处,欢迎交换友链

如果本文对您有帮助,微信扫一扫,请我吃个鸡腿吧