Run and deploy a JHipster project with Java 17
Created: April 5, 2022 9:38 AM
Tags: java, jhipster, spring
In this short article, I’ll explain how to run and deploy a JHipster project using another version than the standard version which is used by JHipster (Java 11 currently).
Step 1: Make it run on the targeted Java version
Use the right Java version locally
Firstly, you need to have the targeted Java version on your local environment. If you are using SDK man you can run:
sdk list java
- Once you have found the target version inside, install it with
sdk install java 17.0.2-open
(for instance) - Finally, run
sdk use java 17.0.2-open
to use it in your current terminal
💡 SDK man is a great tool to manage multiple Java versions on your environment. It allows to easily install versions and switch between versions
Set the right Java version for the project
Once you are using the right Java version locally, you just have to change the target release in the project. If you’re using Maven, you just need to change <java.version>17</java.version>
in the pom.xml
🎉 You are now ready to go, you can try to run the project with ./mvnw
💡 If you see an error saying “Invalid target release 11”, it’s probably that your local and project version are out of sync. They have to be the same (17 in my use case)
Step 2: Fix the CI
If you are using a CI and your CI is using the jhipster/jhipser:latest
Docker image to run the project and the tests, it won’t work anymore because this Docker image is based on eclipse-temurin:11-jre-focal
which is using Java 11.
It means that you will have to recreate your own Docker image based on Java 17, but don’t worry, it’s not complicated:
- Clone the generator-jhipster project on Github
- Open the Dockerfile which is at the project’s root
- Edit the base image to
eclipse-temurin:17-jre-focal
- Create a repository on the docker hub. Let’s assume it’s called
myOrganization/jhipster-java-17
- Build the new image with
docker build . -t myOrganization/jhipster-java-17:latest
- Push the brand new image to the hub with
docker push myOrganization/jhipster-java-17:latest
- Finally, change the docker image used in your CI to
myOrganization/jhipster-java-17:latest
and when your CI reruns, it will succeed.
Step 3: Edit your Cloud environment
At BearStudio, we are using CleverCloud which allows to edit the target Java version very easily thanks the CC_JAVA_VERSION
environment variable, which set up to 17 before saving your changes.
You’re done, your JHipster project should now run on Java 17 🎉
If you don’t use JHipster yet, you can learn how to generate your first project with JHipster with this article (which is in French).
Top comments (0)