Generate Quarkus project with JHipster

Dmytro Chaban
Quarkify
Published in
7 min readMay 22, 2020

For a long time, JHipster used Spring for all the backend logic, once I started to work with Quarkus I always thought how it could be great to have a way to generate Quarkus project with Jhipster. And we finally have it!

In this article, I’ll show you how to generate a new JHipster Quarkus project with angular frontend and complex entity logic with relationships, pagination, and security in just a few minutes. I’ll also guide you through the project structure.

This article also available on Quarkify website

Installing Quarkus blueprint

First of all, we need to install Jhipster’s Quarkus blueprint, it can be done really easy with the next command

npm install -g generator-jhipster-quarkus

This will install required blueprint that we can use later, keep in mind that this project is in active development and you might need to update once the new version is out, you can do it by using the update command.

npm update -g generator-jhipster-quarkus

In case you don’t have JHipster

If you never used or installed jhipster itself, do it by next command:

npm install -g generator-jhipster

Generate Jhipster project

Everything else is super easy, as in any other Jhipster project

jhipster --blueprints quarkus

This will show you many info messages, like in a screen below

At the end of all those messages, you’ll be prompted to fill in some information(gray means default value):

I’ll use quarkify_jhipster as a name of a project, next, you'll be prompted to fill in the package name, I use net.quarkify.jhipster

After that, specify the production database type, as of now we have either SQL or none, let’s use SQL. For database type, let’s use PostgreSQL(Choose whatever you like)

And for development database, which you should specify next, let’s use H2 with disk-based persistency. You can select in-memory one as well

Next, the most interesting part, you need to choose the frontend framework, I’ll choose Angular.

As of this article, I was having issues with React

If you want to change your bootstrap theme, you can choose any of the next prompted themes, I chose darkly with primary navbar theme

Next, select whether you want to have internationalization or not, put Y if you want or n if not. In this example, we won't use it

That’s it, now Jhipster will generate and install all the required dependencies.

Running the app

You can verify if it’s running or not by executing ./mvnw command.

This will build frontend, and serve both frontend and backend, you can go to http://localhost:8080 and see result

Frontend development environment

If you plan to do any changes to frontend or will use JDL import(next section), you’ll need to either rebuild frontend or run development server.

To start development server, simply run npm start in a root folder. you can then go to http://localhost:9000, this will automaticall update and refresh page once you do any changes

To build a static website, that will be later served from Quarkus, run ./mvnw clean compile

Go to account at the top, and put admin as a user and admin as a password, after that, you'll have all the features of an administrator. Keep in mind that some of the features might not work.

Using JML to generate logic

JHipster won’t be a JHipster, if you couldn’t use JDL.

JDL, or JHipster Domain Language, is a domain language with which you can describe entities and relationships between them. This will save hours of your development time if done correctly. Let’s create one JDL schema.

Firstly, go to this gist and copy schema from there. This is really great example for all the features JHipster provides.

Create schema.jh in root of your project and put copied data from the gist. Execute next command below and Jhipster will make everything else for you

jhipster --blueprints quarkus import-jdl schema.jh

If you’ll be prompted with conflict, just put a and hit enter. As we created a new empty application, we don't care about any conflicts. But you should keep in mind that you might need to check the difference in your later versions.

Verify jdl-import result

Execute ./mvnw clean compile and after that use ./mvnw to start the server. Once it's ready, you can open Entities and observe all of the new logic, select Job

You’ll see paginated list of entities. You can also click on Add new Job

As you can see, form already shows you available tasks because you have a relationship from job to task. same thing goes with Employee.

Not sure about you, but I see tons of saved hours. JHipster gives you ability to mix generated and custom code, this way you can generate simple logic at start and after that start working on really important logic that will require hours of work.

Generated project structure

I think it might be really helpful to know how JHipster project is sturctured. It might be good to generate some code, but it will be useless unless you won’t be able to modify it for your needs.

pom.xml

  • /config - package contains constants, jsonb configuration, as well as properties for security and mail
  • /domain - this package contains all the (what a surprise) domain logic, mostly Entities to database and enums
  • /security - Here you can find everything related to security. If you read our article about jwt security. You'll find it very familiar
  • /service - this package, as expected, holds all the service logic. Services are really nicely made as a interfaces, and implementation of them can be found in /service/impl. Besides that, you can find dto and mapper packages, they help to serialize and deserialize data from entity to transfer object.
  • /web/rest - contains all the resources.

I won’t go in details for this file, but you have original quarkus pom.xml setup with large amount of plugins, that help to build frontend, test and more. From quarkus dependencies, you have undertow, resteasy with jsonb, mailer, hibernate with panache and validator, some jdbc dependencies, elytron-security and smallrye-jwt

/java

  1. /config/liquibase is a folder that contains all the migrations. Migrations are also managed by JHipster for any JDL changes, buy you can add your own migrations without any issue
  2. /jwt/privateKey.pem and /META-INF/resources/publicKey.pem is, again, security keys that are used to generate and read JWT tokens, as I described in jwt auth article.
  3. /mail/templates contains email templates in case you'll use mailing

This is probably the most interesting part. JHipster splits logic into such folders:

/resources

Here you can find two really interesting things:

Good word to say is that application.properties are also preconfigured for you.

/webapp

This is “root” folder four frontend application, either it’s React or Angular, they both use TypeScript. I won’t go into details here because we’re mostly interested in backend part

/docker

Here you can find more than just few dockerfiles. You have, additionaly, docker-compose files for different scenarios, such as just postgresql, for monitoring and even sonarqube

In conclusion

I used JHipster previously, and it’s such a pleasure to see the ability to generate Quarkus app. If you won’t use it you might just read the code because it contains many good patterns that can be used later in the development of any project.

Again, it’s not a complete solution but rather a good template that can help you bootstrap your project. You still need to do changes.

Originally published at https://quarkify.net on May 22, 2020.

--

--

Dmytro Chaban
Quarkify

Software Engineer, addicted to productivity and automatization