CLEAR Java Development Guide
Introduction
Java is a widely used programming language for software development, enterprise applications, web services, and academic coursework. The CLEAR computing environment provides multiple Java Development Kit (JDK) versions, along with Apache Maven, to support application development, project management, and automated builds.
This guide provides instructions for configuring Java and Maven on the CLEAR systems, selecting non-default Java versions, and building Java applications using the available development tools. For most users, configuring Java or Maven for the current terminal session or application is recommended because it avoids affecting other courses or projects.
Java 11
Java 11
Java 11 is available on the CLEAR systems. It is not the system default, so you must configure your environment to use Java 11 when needed.
Quick Start
To use Java 11 for your current terminal session, run:
export PATH=/usr/lib/jvm/jre-11/bin:${PATH}
Verify the active Java version with:
java -version
Per Session or Terminal
After establishing an SSH session to a CLEAR system, run:
export PATH=/usr/lib/jvm/jre-11/bin:${PATH}
This modifies the PATH for the current terminal session. If you open another SSH session or close and reopen your terminal, you must run the command again.
Per Application
You can also use a shell script to configure Java 11 specifically for an application. This allows the application to use the required Java environment without permanently changing your login environment.
The following example creates and runs a simple Java program.
Create a file named hello.java:
cat > hello.java <<'EOF'
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
EOF
Create a wrapper script named run-app.sh:
cat > run-app.sh <<'EOF'
#!/usr/bin/env bash
# Enable verbose output when started with:
# DEBUG=true ./run-app.sh
[[ ${DEBUG} ]] && set -xvu
# Use Java 11
PATH=/usr/lib/jvm/jre-11/bin:${PATH}
JAVA='java'
# Verify the Java version
${JAVA} -version
# Run the Java application
${JAVA} hello.java
EOF
Make the script executable:
chmod u+x run-app.sh
Run the application:
./run-app.sh
For verbose shell output, run:
DEBUG=true ./run-app.sh
You should see the Java version information followed by:
Hello, World!
Simple Makefile
You can also use a Makefile to configure the Java 11 environment and run the application.
cat > Makefile <<'EOF' export PATH := /usr/lib/jvm/jre-11/bin:$(PATH) run: java -version java hello.java EOF
Note: Make requires a TAB character before each command under the run: target. If the TAB characters do not survive copying and pasting, edit the Makefile and insert a TAB before each java command.
Run the Makefile with:
make
You should see the Java version information followed by the output from the application.
Permanent Configuration
For most students, configuring Java only for the current session or application is recommended. This helps prevent one course or project from affecting another.
If you need to determine your current login shell, run:
echo $SHELL
If you choose to configure Java 11 automatically for future sessions, add the following command to the appropriate shell initialization file:
export PATH=/usr/lib/jvm/jre-11/bin:${PATH}
The appropriate initialization file depends on your shell:
- sh / bash / ksh: ~/.profile or the appropriate shell-specific configuration file
- csh / tcsh: ~/.cshrc or ~/.tcshrc
- zsh: ~/.zprofile or ~/.zshrc
After updating your configuration, log out and log back in, or reload the appropriate configuration file.
If you need to change your default shell, see Modify your default Linux shell.
Maven 3.8.2 with Java 11
Maven 3.8.2 with Java 11
Maven 3.8.2 is available on the CLEAR systems and can be used with Java 11. Neither Maven 3.8.2 nor Java 11 may be the system default, so the appropriate PATH must be configured before using this environment.
Quick Start
To configure Maven 3.8.2 and Java 11 for your current terminal session, run:
export PATH=/usr/lib/jvm/jre-11/bin:/opt/rice/apache-maven-3.8.2/bin:${PATH}
Verify the active versions with:
java -version mvn -version
Per Session or Terminal
After establishing an SSH session to a CLEAR system, run:
export PATH=/usr/lib/jvm/jre-11/bin:/opt/rice/apache-maven-3.8.2/bin:${PATH}
This configures Java 11 and Maven 3.8.2 for the current terminal session. If you open another SSH session or close and reopen your terminal, you must run the command again.
Building an Application
Apache Maven provides tools for building and managing Java projects. If you are new to Maven, see the Maven in Five Minutes guide.
You can also configure the Java and Maven environment within a Makefile:
export PATH := /usr/lib/jvm/jre-11/bin:/opt/rice/apache-maven-3.8.2/bin:$(PATH) build: mvn package clean: mvn clean
Note: Make requires a TAB character before the mvn package and mvn clean commands. If the TAB characters do not survive copying and pasting, edit the Makefile and insert them manually.
Build the project with:
make build
Clean the project with:
make clean
An application-specific wrapper script can also be used to run the resulting Java archive. For example:
#!/usr/bin/env bash /usr/lib/jvm/jre-11/bin/java -jar target/<target_name>.jar "$@"
Replace <target_name> with the name of the JAR file produced by your Maven project.
Permanent Configuration
For most students, configuring Maven and Java only when needed is recommended. If you choose to configure this environment automatically, add the following command to the appropriate shell initialization file:
export PATH=/usr/lib/jvm/jre-11/bin:/opt/rice/apache-maven-3.8.2/bin:${PATH}
After updating your configuration, log out and log back in, or reload the appropriate configuration file.
If you need to change your default shell, see Modify your default Linux shell.
Using Other Java Versions on CLEAR
Using Other Java Versions
The CLEAR systems may have multiple versions of Java installed. Because only one Java version can be the system default, users who need a different version should configure their own environment rather than changing the system-wide Java configuration.
Check the Current Java Version
To see the Java version currently active in your environment, run:
java -version
Find Available Java Versions
Installed Java environments are typically located under:
/usr/lib/jvm
To view the available Java installations, run:
ls -l /usr/lib/jvm
You may see entries for multiple Java versions, such as Java 11 and Java 17. The exact versions available may change as the CLEAR systems are updated.
Use a Different Java Version for the Current Session
For Bash and other Bourne-compatible shells, prepend the desired Java version to your PATH. For example, to use Java 17:
export PATH=/usr/lib/jvm/java-17/bin:${PATH}
Verify the active version with:
java -version
Bash Configuration
If you choose to configure a specific Java version automatically in Bash, add the following to your ~/.bashrc file:
export PATH=/usr/lib/jvm/java-<VER>/bin:${PATH}
Replace <VER> with the desired Java version number. For example:
export PATH=/usr/lib/jvm/java-17/bin:${PATH}
Apply the change to your current Bash session with:
source ~/.bashrc
CSH and TCSH Configuration
For csh or tcsh users, add the following to the appropriate configuration file:
setenv PATH /usr/lib/jvm/java-<VER>/bin:$PATH
Replace <VER> with the desired Java version number.
If ~/.tcshrc exists, tcsh typically uses that file instead of ~/.cshrc. If ~/.tcshrc does not exist, ~/.cshrc may be used.
Apply the configuration to your current session with the appropriate command:
source ~/.tcshrc
or:
source ~/.cshrc
Testing Your Configuration
After configuring your environment, verify the active Java version:
java -version
System-Wide Java Configuration
Do not attempt to use system administration tools such as alternatives to change the system-wide default Java version. CLEAR is a shared multi-user environment, and changing the system default could affect other users and applications.
Instead, select the Java version you need by configuring your own PATH for the current session, application, or user environment.