Starting from February 2019, Oracle JDK updates will require Commercial license if you make any business using Java (eg, you're a Java Developper not spending only your spare time developping with Java).
It includes Java not only on your server, but on your laptop as well.
What's nasty is Java versions will remains free to download since if you use it as an individual/personal use, you
won't be concerned by the commercial aspects of the license.
Reading this article from Oracle changed my view on this statement : I don't think a "silent Java 8 update" will be possible with this important license change, which was my fear. However, you will still be able to download post-january Java 8 distributions on the Oracle website.. so I hope they will make it crystal clear that those new versions will be incompatible with a business activity.
Anyway, updating to OpenJDK builds and leave Oracle (Open)JDK behind remain a good thing to avoid this licensing mess.
If you want to see if you're concerned, it is easy, simply run :
$> java -version
java version "1.8.0_192"
Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)
If the result contains Java HotSpot(TM)
then you're using "Oracle JDK" or "Oracle Open JDK" which are both
concerned by the license above and there are good chances you're going to need an update to OpenJDK.
Note that if you don't plan to update your current Oracle JDK versions to a post-january 2019 release, then you're safe regarding this commercial license constraint. I only feel it risky to do so as you may forget this constraint when you will upgrade your JDK in 6 monthes so ... not a good thing to back off to better blow up
But everything is not that straightforward for a regular Java Developper given that :
- Java 9->11 introduced multiple breaking changes (Java version schemes, Removed APIs like Unsafe etc..)
- Every libs & frameworks didn't released compatibility fixes with these versions yet
- Even if they did, there are chances you didn't upgraded your own dependencies to align on these new released versions (because upgrading dependencies on your app would require non-regression testing and so on...)
=> this is very likely that you will need both Java 8 and Java 11 (LTS) versions installed at the same time on your laptop to be able to both compile and run your new & legacy apps (personnally, I bet I'm going to need Java 8 for my legacy apps for a long long time, and will dedicate Java 11 to my newly-created apps only).
This document will help you to upgrade if you're a Mac User (I am a Mac user and tried to see the most common paths for this platform for the upgrade).
Linux & Windows users may find this guide useful though there will be differences mainly due to package managers (Windows users can rely on Chocolatey if they want a friendly package manager).
But the idea will remain the same : try to install multiple OpenJDK versions at the same time, and easily switch between it through either jenv
or alternatives
.
This article describes how to install JDKs using Homebrew which is Mac-only. Some other cross-platform solutions exists : SDKMAN! and jabba allow to both install & switch between multiple versions of the JDK both for Mac / Linux / Cygwin(SDKMAN!)|Powershell(jabba) with the limitation of changing system-wide jdk for jabba.
First, make sure you installed :
-
Homebrew : see installation instructions on the Homebrew website (spoiler alert : you will need command line tool for XCode prior to install it)
-
Homebrew cask : once you have installed Homebrew, you will need access to cask formulae (=packages).
Cask formulae are used for non-CLI packages (as soon as you need interactions outside the terminal, typically for applications).
To install Cask, simply run :$> brew tap caskroom/cask
-
jenv : it is a useful utility aimed at managing/switching between multiple jdk versions on your system.
To install it, you can follow installation instructions or simply run :$> brew install jenv # Replace `.bash_profile` by `.zshrc` if you're using zshrc, or any bootstrapping bash script either way # Those lines are important to have jenv being executed during your shell bootstrap $> echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile $> echo 'eval "$(jenv init -)"' >> ~/.bash_profile
If you only need to install OpenJDK 11, then it's super easy, simply run :
$> brew cask reinstall java
And that's it.
Note that by doing this, I'm not sure of the behaviour of cask when a new non-LTS Java (ex: Java 12) version will be released. I guess there will be some java-lts formulae which will be created soon or later to avoid auto-upgrades to non-LTS versions but it doesn't seem to be in place for now.
Personally, I will prefer to explicitely install targetted versions (see section below)
If you need to install AdoptOpenJDK, then it's straightforward :
$> brew tap AdoptOpenJDK/openjdk
# List of available versions is available here : https://github.com/AdoptOpenJDK/homebrew-openjdk
$> brew cask install adoptopenjdk8
$> brew cask install adoptopenjdk11
On AdoptOpenJDK Website you will be able to download Windows and Linux distributions as well.
Also, I'm focusing on AdoptOpenJDK versions as this represents the largest distribution (multiple JDK version across multiple platforms) but other vendors are also providing their own (free) distributions such as Azul, IBM/Red Hat, Amazon or Bellsoft
First, declare instaled jdk versions into your jenv catalog :
# If you installed latest JDK with homebrew
$> jenv add /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/
# For adopt openjdk versions
$> jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/
$> jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.1.jdk/Contents/Home/
Then declare your system-wide used JDK :
# Showing available jdk versions added to the catalog
$> jenv versions
# Declaring global (system-wide, user specific) used jdk
$> jenv global 1.8
If you want to override system-wide JDK on a specific project, then :
$> cd /path/to/my/jdk11/new/project/
$> jenv local 11.0
This will create a /path/to/my/jdk11/new/project/.java-version
file.
Behaviour of jenv
is simply to redefine java*
commands by looking at those .java-version
files
(in current dir and, if not found, in parent directories through the root dir ... then falling back on system-wide
selected jdk when no .java-version
file is found) and updating the good JAVA_HOME
path.
Build tools (Maven, Gradle etc.) integration is available through jenv plugins, more on this on the jenv readme
I want to thank a lot :
- Homebrew & Homebrew cask folks : it's a pleasure to work with homebrew/cask packages on a Mac ! Never had any issue with this package manager.
- AdoptOpenJDK folks who make a great job at freely providing openjdk builds to the community.
- Gildas Cuisinier for his wonderful
jenv
utility - Matt Raible for sharing Oracle Java SE Releases FAQ on his article about Which Java SDK to use
- @marc0der & @davinkevin for mentioning SDKMAN! and jabba alternatives to the Homebrew installation path
Great post !
A few suggestions:
o cask has to be installed
o it would be good to inform people about how to install homebrew, cask and jenv
o when installing a new Java version, you will have to provide the exact name when adding it to jenv. Typically, I just installed the latest Java 11 (adoptopenjdk-11.0.1.jdk) and running 'jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home/' does not work, you have to run 'jenv add /Library/Java/JavaVirtualMachines/adoptopenjdk-11.0.1.jdk/Contents/Home/'