DEV Community

Cover image for Upgrade your JHipster project to Java 17
Quentin Lerebours
Quentin Lerebours

Posted on

6 3

Upgrade your JHipster project to Java 17

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).

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay