How to install Java and Maven on FreeBSD

By Andres Jaimes

- 3 minutes read - 503 words

FreeBSD is a powerful and reliable operating system that is widely used by developers and system administrators. If you are a Java developer, you will need to install both Java and Maven on your FreeBSD system to build and run your Java applications. In this post, we will walk you through the steps to install Java and Maven on FreeBSD.

Java

We will start by switching to the root account, and installing java. The flavor to use is openjdk.

su -
pkg search openjdk
pkg install openjdk19
=====
Message from openjdk19-19.0.1+10.1:

--
This OpenJDK implementation requires fdescfs(5) mounted on /dev/fd and
procfs(5) mounted on /proc.

If you have not done it yet, please do the following:

  mount -t fdescfs fdesc /dev/fd
  mount -t procfs proc /proc

To make it permanent, you need the following lines in /etc/fstab:

  fdesc /dev/fd   fdescfs   rw  0 0
  proc  /proc   procfs    rw  0 0

To complete the installation we have to mount the two file systems described in the instructions:

mount -t fdescfs fdesc /dev/fd
mount -t procfs proc /proc

And add them to the /etc/fstab file. Use vi to do it:

vi /etc/fstab
# Device                Mountpoint      FStype  Options         Dump    Pass#
...
fdesc                   /dev/fd         fdescfs rw              0       0
proc                    /proc           procfs  rw              0       0

Done. Next step is Maven.

Maven

The process for maven is very similar. You will notice that openjdk 8 is installed along maven. This is ok.

pkg install maven
This OpenJDK implementation requires fdescfs(5) mounted on /dev/fd and
procfs(5) mounted on /proc.

If you have not done it yet, please do the following:

  mount -t fdescfs fdesc /dev/fd
  mount -t procfs proc /proc

To make it permanent, you need the following lines in /etc/fstab:

  fdesc /dev/fd   fdescfs   rw  0 0
  proc  /proc   procfs    rw  0 0

At the end of the process, we will get a message similar to the one we got for openjdk 19. It is safe to skip because we have already mounted and configured the file systems in the previous step.

Running the apps

End the root session and go back to your regular user prompt. The final step of this process is to validate that both java and maven work. To validate java type:

java -version
openjdk version "19.0.1" 2022-10-18
OpenJDK Runtime Environment (build 19.0.1+10-1)
OpenJDK 64-Bit Server VM (build 19.0.1+10-1, mixed mode, sharing)

And for maven:

mvn -version
Apache Maven 3.8.7
Maven home: /usr/local/share/java/maven
Java version: 19.0.1, vendor: OpenJDK BSD Porting Team, runtime: /usr/local/openjdk19
Default locale: en, platform encoding: UTF-8
OS name: "freebsd", version: "13.1-release", arch: "amd64", family: "unix"

Conclusion

Installing Java and Maven on FreeBSD is a simple and straightforward process that can be completed in just a few easy steps. By following the steps outlined in this post, you’ll be able to set up a fully functional Java development environment on your FreeBSD system in no time. With Java and Maven installed, you’ll be able to build and run your Java applications with ease, and take advantage of the many benefits that FreeBSD has to offer.