Let's create a simple java app which returns text and available on port 1800 of your local environment using Docker container in 5 minutes (depends on your internet connection speed).
You can always grab the full source code from my public repository:
https://github.com/alexander-uspenskiy/simple-service
Dependencies Setup
Step 1: Prerequisites
- Install Java 8
- Install Maven
- Install Docker
- Install VS Code + Extensions
Mac Installation
# Install Homebrew if not present
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Java 8
brew tap homebrew/cask-versions
brew install --cask temurin8
# Install Maven
brew install maven
# Install Docker Desktop
brew install --cask docker
# Install VS Code
brew install --cask visual-studio-code
# Install VS Code Extensions
code --install-extension vscjava.vscode-java-pack
code --install-extension ms-azuretools.vscode-docker
Windows Installation
# Install Chocolatey if not present
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Install Java 8
choco install temurin8
# Install Maven
choco install maven
# Install Docker Desktop
choco install docker-desktop
# Install VS Code
choco install vscode
# Install VS Code Extensions
code --install-extension vscjava.vscode-java-pack
code --install-extension ms-azuretools.vscode-docker
Project Setup (Both Platforms)
# Create project structure
mkdir -p simple-service/src/main/java/com/example
cd simple-service
# Copy files
# Copy App.java to src/main/java/com/example/
# Copy pom.xml to project root
# Copy Dockerfile to project root
# Build and run
mvn clean package
docker compose up
VS Code Settings
{
"java.configuration.runtimes": [
{
"name": "JavaSE-1.8",
"path": "/Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home",
"default": true
}
],
"java.configuration.updateBuildConfiguration": "automatic",
"java.compile.nullAnalysis.mode": "automatic",
"maven.executable.path": "/usr/local/bin/mvn"
}
Verify Installation
# Verify Java
java -version
# Verify Maven
mvn -version
# Verify Docker
docker --version
Project Setup
# Create Maven project
mvn archetype:generate \
-DgroupId=com.example \
-DartifactId=simple-service \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DarchetypeVersion=1.4 \
-DinteractiveMode=false