Java developer setup for learning and experiments
Working with multiple Java versions
As of now, there are still applications that work only with JDK 8. There are other applications that work with JDK 11 max. There are few which work on latest & greatest Java 16. Having a local setup to easily switch between them will be very handy.
The following steps are indented for Linux & Mac. I haven’t tried this on Windows for this problem.
jEnv
jEnv — is an amazing command line tool that can help us.
$ git clone https://github.com/jenv/jenv.git ~/.jenvor$ brew install jenv
To activate jenv, add the following to your ~/.zshrc:
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
Installing Java
jEnv doesn’t support installation from it’s command line tool. We need to install manually different versions of Java we need.
Option 1: direct install from java website or if it’s mac, brew install.
For Mac with M1 chip, it was easier to go with brew since it takes care of system architecture (M1 chip ARM 64 bit) automatically
# Install OpenJDK
brew install openjdk@11
Option 2: use adoptopenjdk to find installables for different system architecture & java versions.
Add Java to Jenv
# Brew installed path example
$ jenv add /opt/homebrew/opt/openjdk@11# Manually installed path example
$ jenv add /Library/Java/JavaVirtualMachines/temurin-11.jdk/Contents/Home
This will add JDK to one of the options. We can see list of jdk installed :
$jenv versions
system
1.7
1.7.0.80
1.8
1.8.0.202
11
11.0
11.0.10
* 15 (set by /Users/sairam/.jenv/version)
15.0
15.0.1
openjdk64-11.0.10
oracle64-1.7.0.80
oracle64-1.8.0.202
oracle64-15.0.1
Configure for this session alone — we can pick our choice from above text
$jenv local 11
Configure globally using
$ jenv global 11
Download maven dependency with transitive dependencies
- `Apache Ivy` is super useful when we need to download a maven dependency and along with it’s transitive dependencies.
- Let’s say I want to download in a dockerFile spark-hadoop-cloud jar with it’s transitive dependencies. We don’t have to install maven just for this need. We could use `Apache Ivy`
curl -L -O https://repo1.maven.org/maven2/org/apache/ivy/ivy/2.5.0/ivy-2.5.0.jarjava -jar ivy-2.5.0.jar -dependency org.apache.spark spark-hadoop-cloud_2.13 3.3.0 -retrieve "lib/[artifact]-[revision](-[classifier]).[ext]"