Maven and Java 21

I have a project that I’m working on soon, that’s going to be a Java Spring Boot application, I know you wouldn’t think that I’m a Java developer looking at most of my repositories. I’ve not actually set up Maven and Java on this machine yet so I thought I’d document it while I go along. It’s worth noting that I’m not using the version of maven within the distribution repositories as it’s a little outdated, and I’m going to be using an Oracle JDK which is how this set up differs from standard.

First I’m going to need a Java JDK, I’ve choosen to use an Oracle JDK and Java 21. It’s simple to get, just use wget to download the file, then install the .deb.

1
2
3
4
5
6
7
wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.deb
sudo apt install ./jdk-21_linux-x64_bin.deb
java --version
---------
java 21.0.4 2024-07-16 LTS
Java(TM) SE Runtime Environment (build 21.0.4+8-LTS-274)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.4+8-LTS-274, mixed mode, sharing)

Now that Java is installed and the version displayed is correct I can move on to installing Maven, which is basically the same method, not using apt get but getting the binaries and installing them.

1
2
3
4
5
sudo apt-get remove maven # first remove any old versions you may have installed
wget https://downloads.apache.org/maven/maven-3/3.9.8/binaries/apache-maven-3.9.8-bin.tar.gz
tar -xvzf apache-maven-3.9.8-bin.tar.gz
sudo mv apache-maven-3.9.8 /opt/
sudo ln -sfn /opt/apache-maven-3.9.8 /opt/maven

This will set up maven on the system, however it’s not on the path next I’ll append the following lines my bash profile.

1
2
export M2_HOME=/opt/maven
export PATH=$M2_HOME/bin:$PATH

Then reload the profile.

1
source ~/.bashrc

Now to test that everything is working as expected we should have maven display it’s version with the correct JDK.

1
2
3
4
5
6
7
mvn -v
---------
Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: /opt/maven
Java version: 21.0.4, vendor: Oracle Corporation, runtime: /usr/lib/jvm/jdk-21.0.4-oracle-x64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.15.153.1-microsoft-standard-wsl2", arch: "amd64", family: "unix"

Maven and Java 21 are now configured on my system and I can now start my Java Spring Boot project. 👍


↤ Fixed Bootstrap Freelancer Release
Multiple Python Versions With Tox ↦