Skip to content

Commit

Permalink
fix: Pom and Docker for Java 21
Browse files Browse the repository at this point in the history
Recent update of Java 21 broke the Dockerfile. The pom.xml file is also
broken. Fixing it 🤘
  • Loading branch information
gselig1a committed Dec 12, 2024
1 parent c7d5395 commit 6bfd189
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Step 1: Use an official Maven image to build the project
FROM docker.io/maven:3.8.8-eclipse-temurin-17 AS build
FROM docker.io/maven:3.9.9-eclipse-temurin-21 AS build

# Step 2: Set the working directory inside the container
WORKDIR /app
Expand All @@ -11,7 +11,7 @@ COPY . .
RUN mvn clean package

# Step 5: Use Tomcat image to deploy the WAR
FROM docker.io/tomcat:jdk17
FROM docker.io/tomcat:jdk21

# Step 6: Set the working directory inside the Tomcat container
WORKDIR /usr/local/tomcat/webapps
Expand Down
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,45 +47,36 @@ The `HelloWorldMainLauncherClass` performs the following tasks:

## Prerequisites

- Java Development Kit (JDK) 8 or higher.
- Java Development Kit (JDK) 21 or higher.
- A Java IDE (like IntelliJ IDEA, Eclipse, or NetBeans) or a command-line environment to compile and run the Java program.

## Installation

To set up and run this project locally, follow these steps:

1. Clone the repository:

```bash
git clone https://github.com/NanowarOfSteel/HelloWorld.git
```

2. Navigate into the project sources directory:
```bash
cd HelloWorld/src/main/java
```

3. Compile the Java file:
```bash
javac it/nanowar/ofsteel/helloworld/HelloWorldMainLauncherClass.java
```

4. Run the program:
```bash
javac it/nanowar/ofsteel/helloworld/HelloWorldMainLauncherClass.java
cd HelloWorld
```

Alternatively, with Java 11 you can compile and run the project in one single step:

3. Compile and run the Java file:

```bash
java it/nanowar/ofsteel/helloworld/HelloWorldMainLauncherClass.java
java src/main/java/it/nanowar/ofsteel/helloworld/HelloWorldMainLauncherClass.java
```

## Usage

Once you run the program, you will see the following output:

```
```text
Hello World Programmer Start
Hello World!
Hello World!
Expand Down Expand Up @@ -211,13 +202,14 @@ in the root directory of the project, then point out the location of the
Dockerfile with the `-f` option:

```bash
docker build -t my-java-app -f src/main/docker/helloworld.dockerfile .
docker build -t my-java-app .
```

This command will:

1. Use an official Maven image to build the application.
2. Package the application into a JAR file.
3. Use a slim OpenJDK 17 image to run the resulting application (**kinda**).
3. Use a slim OpenJDK 21 image to run the resulting application (**kinda**).

## Usage

Expand Down
30 changes: 10 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<artifactId>HelloWorld</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>
<build>
<plugins>
Expand All @@ -24,14 +24,17 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<warName>nano</warName>
</configuration>
</plugin>
</plugins>
</build>
<packaging>war</packaging>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
Expand All @@ -52,17 +55,4 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<warName>nano</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 6bfd189

Please sign in to comment.