Here's a Dockerfile that uses Maven 4 and JDK 23:
FROM eclipse-temurin:23-jdk-jammy
# Set Maven version
ENV MAVEN_VERSION 4.0.0
ENV MAVEN_HOME /usr/share/maven
ENV MAVEN_CONFIG "/root/.m2"
# Install Maven
RUN apt-get update && \
apt-get install -y curl && \
mkdir -p /usr/share/maven /usr/share/maven/ref && \
curl -fsSL https://dlcdn.apache.org/maven/maven-4/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz \
| tar -xzC /usr/share/maven --strip-components=1 && \
ln -s /usr/share/maven/bin/mvn /usr/bin/mvn && \
# Clean up
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy application files (if needed)
# COPY . .
# Default command
CMD ["mvn", "--version"]
This Dockerfile:
- Uses Eclipse Temurin's JDK 23 as the base image
- Installs Maven 4.0.0
- Sets up necessary environment variables
- Creates a working directory for your application
You can build this image with:
docker build -t maven4-jdk23 .
And run it with:
docker run -it maven4-jdk23
Would you like me to explain any part of this Dockerfile in more detail?
Here's an updated Dockerfile that builds a Maven application, copies the Java app, and runs it:
This Dockerfile:
mvn clean package
To use this Dockerfile:
docker build -t my-java-app .
docker run -it my-java-app