Getting Started
To work successfully with the programs needed for PRC2, you need to install them first. Properly installing Java and other programs is not hard but must be done precisely. What will follow is a description on how to do that under Ubuntu Linux, macOS and Windows. You can adapt this configuration for other operating systems too, possibly with a few tweaks.
Warning:
Before you install any software from the internet, please validate the the package. You typically see signature files such as SHA-256 or PGP-ASC, os something similar, which can help to ascertain that the package is the one you think it is. For instance with:
$ sha512sum /path/to/file
$ shasum -a 256 /path/to/file
$ certUtil -hashfile /path/to/file SHA256
You can check the download of that version of your IDE, and the command should produce the same signature as is available on the download website.
Setting up the correct environment
Install Java
The default installation paths are:
/usr/lib/jvm
/Library/Java/JavaVirtualMachines/
C:\Program Files\AdoptOpenJDK\
Warning:
Do NOT use Program Files
under Windows, because of the space in the name,
but instead create a separate directory simply called
e.g. c:\usr\lib\jvm
if you insist on using Windows.
On other OSs it is also important to make sure paths do NOT contains spaces,
as spaces are also used as separators for arguments
Installation of Java can be done either through a package manager or by downloading the the Java distribution from AdoptOpenJDK . For PRC2 we will use Java 21.
Linux
With a package manager:
sudo apt install openjdk-21-jdk
apt-get install -y wget apt-transport-https gnupg
wget -O - https://packages.adoptium.net/artifactory/api/gpg/key/public | apt-key add -
echo "deb https://packages.adoptium.net/artifactory/deb $(awk -F= '/^VERSION_CODENAME/{print$2}' /etc/os-release) main" | tee /etc/apt/sources.list.d/adoptium.list
apt-get update # update if you haven't already
apt-get install temurin-21-jdk
Manual installation:
In the example below we assume that the distribution is packed as a tar.gz
archive.
The example shows the archive name as of 21 January 2024,
OpenJDK21U-jdk_x64_linux_hotspot_21.0.2_13.tar.gz
sudo mkdir -p /usr/lib/jvm
cd /usr/lib/jvm
sudo tar xf ~/Downloads/OpenJDK21U-jdk_x64_linux_hotspot_21.0.2_13.tar.gz
macOS
With HomeBrew:
# Untap AdoptOpenJDK first
brew untap AdoptOpenJDK/openjdk
# If you want to download latest version
brew install --cask temurin
# To install specific version
brew tap homebrew/cask-versions
brew install --cask temurin21
Manual installation:
Download the correct distribution/version of choice from AdoptOpenJDK . Install the same way as normal programs.
Windows
Install with the Windows Package Manager:
First install the winget
winget install Microsoft.OpenJDK.21
Manual installation:
Download the correct distribution/version of choice from AdoptOpenJDK . Install the same way as normal programs,
Warning:
Do NOT forget to change the install path during installation.
e.g. C:\usr\lib\jvm\
Also make sure to check Add to path and Add JAVA HOME.
Make Java available on the PATH
If you used a package manager or an installer to install Java, then Java should already be added to your path. However if you manually extracted the binaries then you should still add Java to the path.
The $PATH
environment variable is used by the command line processor to find the commands or programs whose name you type as first word in a command line.
If you type java -version
, and your shell says command not found
, then your path does not include the java program yet.
Since we want the best Java experience, we will use some common environment variables.
Linux
JAVA_HOME Define JAVA_HOME first. That will help Java, but also tell other programs to find the desired Java version.
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 1
export JAVA_HOME=/usr/lib/jvm/temurin-17-jdk 2
- Path for manual installation
- Path for package manager installation
PATH Prepend the directory under JAVA_HOME to your path, so all java related programs, such as java
, javac
, jar
etc can be found, by just typing the name.
export PATH=${JAVA_HOME}/bin:$PATH
To avoid having to do this every time you start the command-line, add the commands to your /.bashrc
//.zshrc
script file, at the bottom.
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=${JAVA_HOME}/bin:$PATH
To switch Java versions use the following command:
sudo update-alternatives --config java
macOS
These instructions will guide you to setup the correct environment on macOS and to make it easy to switch between Java versions.
/usr/libexec/java_home
/usr/libexec/java_home -V
The first command lists the most recent version of Java on your system The second command lists all installed versions of Java on your system
We can now setup an environment to easily switch between Java versions and later on even launch most IDEs with the intended Java version.
The only thing we need to do for this is set the JAVA_HOME
environment variable to link to the correct Java version.
JAVA_HOME
environmentexport JAVA_HOME=<path_to_java_home>
Where the <path_to_java_home> can be obtained by the command above with the -V parameter.
JAVA_HOME
is set correctlyecho $JAVA_HOME
However instead of hardcoding the path it is better to retrieve the path while setting the environment.
JAVA_HOME
dynamically with the following command (e.g. for Java 15):export JAVA_HOME=$(/usr/libexec/java_home)
$() means that the invocation between parenthesis is resolved first.
This sets the correct Java environment for your current Terminal session. When opening a new terminal the default Java environment will be active again. To make switching between Java versions in the terminal easier we can set-up what is called an alias. An alias is basically a shortcut, you specify the keyboard shortcut and which commands should be executed. We want these aliases to always be available, for this we need to let the terminal know to load our aliases on startup. Depending on the type of terminal you are using, we need the specify the aliases at different places.
Since macOS Catalina (10.15) the default shell (which is used by the terminal) is ZShell (zsh).
This means we can specify our aliases in either .zshrc
or in .zprofile
in our home directory. We suggest to
create an additional configuration file .java_setup
in your home directory.
# Include java environment setup
source .java_setup
# Set your default JAVA_HOME
export JAVA_HOME=$(/usr/libexec/java_home -v 17.0.6)
alias j11="export JAVA_HOME=`/usr/libexec/java_home -v 11.0.12`; java -version"
alias j17="export JAVA_HOME=`/usr/libexec/java_home -v 17.0.6`; java -version"
alias j21="export JAVA_HOME=`/usr/libexec/java_home -v 21.0.2`; java -version"
# Add maven to path
export PATH=/Applications/maven/apache-maven-3.9.0/bin:$PATH
We now need to either restart the terminal for the aliases to take effect or source the .zshrc
file:
source ~/.zshrc
We can now check that switching between versions works:
java -version
j11
j17
j21
Check that the default Java version is correct Check that switching between versions works Check that switching between versions works Check that switching between versions works
Now we have set-up a way to easily switch between Java versions in the terminal.
Windows
Java should already be added to the path by the installer, as it is a default setting during installation.
Install Apache Maven
We will use Apache Maven, or maven for short throughout the PRC2 course, so you will need that too.
The application is called Maven but as command spelled as mvn
.
Maven is the default build tool in the Java world and can build your program from sources without the use of and IDE. This makes your project agnostic to the IDE used. Most IDEs will detect your project as a maven project if the pom.xml
file is present in the root of your project.
Maven is also the way the teachers use to compile and test the students work for the practical assignments and performance assessments.
Linux
Install with package manager:
sudo apt install maven
Install manually:
Fetch a fresh copy of Apache Maven from the website.
To install it, do (example uses version 3.9.6 as of 2024-01-21)
cd /usr/share
sudo rm -fr maven
sudo tar xf ~/Downloads/apache-maven-3.9.6-bin.tar.gz
sudo ln -sf apache-maven-3.9.6/ maven
cd /usr/bin
sudo ln -sf ../share/maven/bin/mvn .
Once this is done, entering mvn --version
should produce output.
macOS
Install with HomeBrew:
brew install maven
Install manually:
Fetch a fresh copy of Apache Maven from the website. Unzip the archive at an appropriate location (e.g. /Applications). Make sure to put maven on the path, see java_setup.
Once this is done, entering mvn --version
should produce output.
Windows
Install with Chocolately:
choco install maven
Install manually:
- Download the zip file from https://maven.apache.org/download.cgi.
- Extract the zip file to
C:\usr\lib
- Add the
bin
directory to thepath
- Goto
Settings > About > Advanced System Settings > Advanced Tab > Environment Variables
- Select
Path
andEdit
New
and fill in the pathC:\usr\lib\apache-maven-3.6.3\bin
- Goto
- Close
System Properties
- Start
cmd
mvn -v
should return a version
Install or update your IDE
The official Java IDE at Fontys ICT Venlo is Apache NetBeans IDE. The latests version for the moment is 20.0.
Linux
You can either install Netbeans from Ubuntu Software (Snap) or download the binaries.
To install the binaries of Apache NetBeans on Ubuntu simply fetch the binary as zip file and unpack it,
then either add the contained bin directory to the path, or make a wrapper netbeans
command in your personal ~/bin
directory.
For my installation I simply used the binaries, in the zip file, and install it
in the traditional (as in same directories as the installer would) /usr/local
.
/opt
is also a good choice as installation directory.
cd /usr/local
sudo unzip ~/Downloads/netbeans-20-bin.zip
sudo mv netbeans{,-21}
For extra creature comfort, add a simple netbeans script to your path
#!/usr/bin/env bash
/usr/local/netbeans-20/bin/netbeans "$@" & 1
- Invoke netbeans using its absolute path.
Then make that script executable with chmod +x netbeans
.
NetBeans IDE should now be runnable from the command line (fine for me) as well as from the menu.
macOS
It is possible to install Netbeans by downloading the installer, manual extracting the binaries or by using HomeBrew.
Installing with the installer:
- Download the installer from https://netbeans.apache.org/download/index.html
- Install as normal
brew install --cask netbeans
Installing the binaries manually, see installation guidelines for maven on MacOS.
As an extra we can start Netbeans from the command-line using the Java version we want to use.
We do this by adding an executable file to the PATH
so we can start Netbeans from the terminal with the correct Java version.
netbeans
file in /usr/local/bin
cd /usr/local/bin 1
touch netbeans 2
echo \"/Applications/NetBeans/Apache\ NetBeans\ 21.app/Contents/Resources/NetBeans/netbeans/bin/netbeans\" --jdkhome
\$JAVA_HOME \$\* \& > netbeans 3
chmod +x netbeans 4
- Change to the right directory
- Create new file called netbeans
- Write the correct command into netbeans
- Make the file executable
As you can see, when invoking it this way, you can inform Netbeans about which java version to use (as set in your JAVA_HOME
environment variable).
Furthermore you can pass the project name as a parameter (defined by $*`
) so you don’t need to open the project manually anymore in NetBeans.
Finally the &
means that NetBeans runs as a background process without blocking your Terminal session, so your Terminal session is immediately available again.
myProject
in Netbeans using Java version 17j17
netbeans myProject
Windows
- Download the installer from https://netbeans.apache.org/download/index.html
- Install as usual, make sure to change to
path
Other IDE’s
We use NetBeans IDE as default. We might not be able to answer any support questions on other IDE’s. You are free to choose your own Integrated Development Environment (IDE). An IDE allows you to write, compile, run and debug your programs in one place. Popular choices are: