diff --git a/howto/get-java.md b/howto/get-java.md new file mode 100644 index 0000000000000000000000000000000000000000..c2aa8440977b0f7921fcb3c8275e67e032789fbc --- /dev/null +++ b/howto/get-java.md @@ -0,0 +1,267 @@ +# Setting up Java + + + +To be able to develop in Java one requires a JDK - Java Development Kit. You have to download and properly set up java +For IT1901 either JDK 11 or 12 will do just fine. + + +## Install java + +If there is no Java Development Kit installed or the version is not what you need (we recommend version 11 or 12) then proceed to download JDK and install it. + +### Windows + +#### Check if there is any java installed + +In a command line window type: + +``` batch +java -version +``` + + +#### Extract downloaded binary + +After the download finishes you have in the destination folder the `.zip` file with a name like this `openjdk-12.0.2_windows-x64_bin.zip`. Right click it and extract the contents. + + + +Copy the extracted folder in a meaningful location on your hard drive like for example in `C:\jdks` + + + + +#### Set up the environment variables + +To properly set up Java on your machine you need to set couple environment variables. To do that you need to open "Environment variables" dialog box. +There are several ways to get to that dialog box. + +Right click "This PC" and select "Properties" + + + +You should see a window like the one below. Choose "Advanced System Settings" option in the top left side. + + + +A new window will open showing "System properties" + + + +Open "Environment Variables" + +If the JDK should be available for all users than make the environment variable changes at system level otherwise do them at user level. + +Check if there is already a `JAVA_HOME` environment variable. If it is change the value to the path to your JDK (`C:\jdks\jdk-12.0.2`) + + + +Next we need to add the `bin` folder within the JDK folder to the `PATH` environment variable so that the java commands are accessible from the command prompt + + + +Finally we can check if java is now running as expected + + + +##### Notes + +* You can check the values of environment variables from command prompt issuing commands such as `SET JAVA_HOME` or `SET PATH` +* You can get to the environment variable dialog by other means + - search "env" in the windows start menu + - open System from the Control Panel and then "Environment Variables" + + +### Linux + +#### Check if there is any java installed + +Open a terminal window and type + +``` bash +java -version +``` + +#### Extract downloaded binary + +After the download finishes you have in the destination folder the `.tar.gz` file with a name like this `openjdk-12.0.2_linux-x64_bin.tar.gz` . + +Extract the files and place them in the desired location with the following commands + + +``` bash +tar zxvf openjdk-12.0.2_linux-x64_bin.tar.gz +sudo mkdir /usr/lib/jvm +sudo mv jdk-12.0.2 /usr/lib/jvm/ +``` + +#### Set up the environment variables + +create a shell script in /etc/profile.d + +``` bash +sudo nano /etc/profile.d/jdk.sh +``` + +add the following lines inside the file and save and close + +``` bash +export JAVA_HOME=/usr/lib/jvm/jdk-12.0.2 +export PATH=$PATH:$JAVA_HOME/bin + +``` + +apply changes + +logout and log back in or run the script you have just created + +``` bash +bash /etc/profile.d/jdk.sh +``` + + +check if everything is in order + +``` bash +echo $JAVA_HOME +java -version +``` + + + +### MacOs + +#### Check if there is any java installed + +Open a terminal window and type + +``` bash +java -version +``` + +#### Extract downloaded binary + +After the download finishes you have in the destination folder the `.tar.gz` file with a name like this `openjdk-12.0.2_osx-x64_bin.tar.gz`. + +Extract the files using the following command + +``` bash +tar xf openjdk-12.0.2_osx-x64_bin.tar.gz +``` + +Move the extracted to the folder `/Library/Java/JavaVirtualMachines/` +You will need to execute the move with super user privileges in order to put the files in the system folder + +``` bash +sudo mv jdk-12.0.2 /Library/Java/JavaVirtualMachines/ +``` + + +#### Set up the environment variables + +To set up the environment variable `JAVA_HOME` we will need to edit the `.bash_profile` file in the home directory. + +If the file mentioned does not exist we can create it with the following command: + +``` bash +touch ~/.bash_profile +``` + +We need to export the `JAVA_HOME` variable so we edit the file using + +``` bash +edit ~/.bash_profile +``` + +we add the following line + +`export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk-12.0.2/Contents/Home"` + +finally we save the changes and close the file. To apply the changes we need to run the following command + +``` bash +source ~/.bash_profile +``` + + +## Using sdkman + +sdkman is a tool that allows you to manage development kits including JDK. It is possible to run it on Linux and Mac without additional software. On windows one can use it after installing Git Bash and MinGW. +Refer to the https://sdkman.io webpage for more info and instructions + +### Installation on supported systems - open a terminal window and enter: + +``` bash +curl -s "https://get.sdkman.io" | bash +``` + +Follow the instructions on-screen to complete installation. + +Apply changes by entering: + +``` bash +source "$HOME/.sdkman/bin/sdkman-init.sh" +``` + +check the version using the command + +``` bash +sdk version +``` + +If the tool is now properly installed the result of the previous command will be: + +``` bash + sdkman 5.x.x +``` + + +### Typical usage + +After installation you will typically use commands like + +``` bash +sdk list java +``` +list the available versions + +``` bash +sdk install java +``` +install latest java, add version number to install specific java + +``` bash +sdk use java 12.0.2 +``` +use the java development kit with version 12.0.2 + + +See more commands on the sdkman.io site + + + +## Download Java + + +### Open-source reference implementation (GNU GPL License, provided by Oracle) + +* 1. go to http://jdk.java.net + + + +* 2. select the general available build (currently 12) + + + +* 3. download the binary corresponding to your operating system + + +### Get binaries from Oracle site (Oracle license) + +1. go to https://www.oracle.com/technetwork/java/javase/downloads/index.html +2. sign in (if you do not have an account you will need to create one in order to be allowed to download) +3. select the latest (currently 12) +4. download the binary corresponding to your operating system + +There are more choices for downloads. Typically a .zip or .tar.gz would imply manual setup while the .exe, .deb, .rpm, .dmg will provide some sort of installer support. diff --git a/howto/images/01 - jdk.java.net - home.png b/howto/images/01 - jdk.java.net - home.png new file mode 100644 index 0000000000000000000000000000000000000000..8282dc482f4a5379cbad4668f5c5c37c29f38be8 Binary files /dev/null and b/howto/images/01 - jdk.java.net - home.png differ diff --git a/howto/images/02 - jdk.java.net - latest ga.png b/howto/images/02 - jdk.java.net - latest ga.png new file mode 100644 index 0000000000000000000000000000000000000000..ce8e652114fa913a252db5a2e9bf5dea72594643 Binary files /dev/null and b/howto/images/02 - jdk.java.net - latest ga.png differ diff --git a/howto/images/03 - jdk.java.net - get windows binary.png b/howto/images/03 - jdk.java.net - get windows binary.png new file mode 100644 index 0000000000000000000000000000000000000000..db41622d9d9e15b2d259e99364ed648d33165436 Binary files /dev/null and b/howto/images/03 - jdk.java.net - get windows binary.png differ diff --git a/howto/images/04 - check for java windows.png b/howto/images/04 - check for java windows.png new file mode 100644 index 0000000000000000000000000000000000000000..d0adea979bb8686773d8322008c8a0b01769a786 Binary files /dev/null and b/howto/images/04 - check for java windows.png differ diff --git a/howto/images/05 - extract openjdk windows.png b/howto/images/05 - extract openjdk windows.png new file mode 100644 index 0000000000000000000000000000000000000000..9cc7bdd83f4027f3d5691edbe9ae5aa3ae8e8f36 Binary files /dev/null and b/howto/images/05 - extract openjdk windows.png differ diff --git a/howto/images/06 - move the jdk folder to c-jdks folder.png b/howto/images/06 - move the jdk folder to c-jdks folder.png new file mode 100644 index 0000000000000000000000000000000000000000..6fbbbbdbaf0d9d54bd24f350b744e6eee83a9c8c Binary files /dev/null and b/howto/images/06 - move the jdk folder to c-jdks folder.png differ diff --git a/howto/images/07 - open pc properties.png b/howto/images/07 - open pc properties.png new file mode 100644 index 0000000000000000000000000000000000000000..649ef30db0f93d3c3f7cbbdfe271856b74d0ea18 Binary files /dev/null and b/howto/images/07 - open pc properties.png differ diff --git a/howto/images/08 - pc properties window.png b/howto/images/08 - pc properties window.png new file mode 100644 index 0000000000000000000000000000000000000000..627128fd4952f1f6059805f6e7b48c1900272f41 Binary files /dev/null and b/howto/images/08 - pc properties window.png differ diff --git a/howto/images/09 - system properties.png b/howto/images/09 - system properties.png new file mode 100644 index 0000000000000000000000000000000000000000..0c0dad83ac78d46b314bde578e75b0772a243b30 Binary files /dev/null and b/howto/images/09 - system properties.png differ diff --git a/howto/images/10 - env java home.png b/howto/images/10 - env java home.png new file mode 100644 index 0000000000000000000000000000000000000000..9079b186976da5786f5a7fba4d366720f09ec236 Binary files /dev/null and b/howto/images/10 - env java home.png differ diff --git a/howto/images/11 - env path.png b/howto/images/11 - env path.png new file mode 100644 index 0000000000000000000000000000000000000000..b2585541ccbc70b439ab450c667b7b6340d2731c Binary files /dev/null and b/howto/images/11 - env path.png differ diff --git a/howto/images/12 - java check ok.png b/howto/images/12 - java check ok.png new file mode 100644 index 0000000000000000000000000000000000000000..7a4a2c2452d0fff51be8f07147ac1344674a208e Binary files /dev/null and b/howto/images/12 - java check ok.png differ diff --git a/howto/logos/java.png b/howto/logos/java.png new file mode 100644 index 0000000000000000000000000000000000000000..9f75a07f36a55196ebe74f26bb51e1152a5f9e44 Binary files /dev/null and b/howto/logos/java.png differ