Updated: 23 March 2024
Create file HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World");
}
}
Bash into the Maven Docker image, which has the JDK and Java pre-installed
docker run -it --rm --name my-maven-project \
-v "$(pwd)":/usr/src/mymaven -w /usr/src/mymaven \
maven:3.8.6-jdk-11 bash
Compile the source file into a class file
javac HelloWorld.java
Run the class file
java HelloWorld