In this post, I will cover and guide you through the necessary steps to generate a JHipster application. JHipster is an opinionated generator that helps you to quickly bootstrap projects using Springboot and different front end frameworks and technology stack. I use it for some of my side projects and to quickly bootstrap applications to study new technologies and prototype solutions. Jhipster is quite flexible and gives you many options, in this and next posts I will write about my most common preferences and customizations when using Jhipster.
For this series, I am picking a JHipster generated microservices-gateway project to start, if you decide to go with a monolithic approach in the following steps most of the customizations and instructions will also apply.
So if you are starting a new serious project and you are not studying distributed microservices systems or isn't familiar with them it is better that you pick a monolithic approach instead when selecting the available Jhipster options, picking that option will not change much from the customizations that I will explain in the next posts here as the monolithic version of the JHipster project has many similarities with the Gateway project I generate in this post.
Jhipster has good documentation so if you find yourself lost here, take a look at their official documentation as your doubts will most likely be already answered there. The version of Jhipster I am using is 6.7.0 for this post.
The first step to generate a Jhipster project is to install all its required dependencies and CLI as explained in their Getting Started guide, to follow up in this post please make sure you have your machine properly set up following the instructions on the link.
Jhipster is a generic generator which enables you to bootstrap your projects and pick many different technology stacks and has many options, what I am doing in this post is guiding you with my opinionated tech stack and choices I like the best for my side projects when using Jhipster and the customizations I normally do to fit my preferences.
- Open a terminal window, navigate to the personal working folder of your preference and create an initial folder to host the project:
mkdir jhipster-custom && cd jhipster-custom
- Start the jhipster generator in the command line:
You will be presented with a list of options to pick, choose
Microservice gateway or
Next step is to choose a base name for your application:
Now you will be prompted to select a port, leave the default:
Define a java package name:
Pick a service discovery option(if you pick the monolithic app option, most likely this one will not be there), it is safe to skip it in this case, if you picked Gateway Application on item 2 select:
Jhipster Registrywhich uses Eureka with Spring Cloud Config support.
Type of authentication:
JWT authentication (stateless, with a token).
SQLand then select
Postgresagain in the development database option.
Cache options pick:
Yes, with the Ehcache implementation.
Use hibernate 2nd level cache:
Maven or Gradle:
None, just hit enter without selecting any for now.
Front End framework:
Nolets stick to Englis for the series.
Nonejust hit enter and skip it, JUnit is already there in the generated project.
Other generators from Marketplace:
After this last selection the project will be generated for you, if it fails, please review and make sure to follow the links above to set up your environment properly.
It will take some time but finally, you should see a message like:
INFO! Congratulations, JHipster execution is complete!. Awesome you have generated your JHipster project, lets now run the initial generated application before we start customizing it.
All commands to run the application next should be executed from the level of the project folder we created initially.
To run the generated project you will first need to run the Postgresql database so your application can connect to it, luckily Jhipster is shipped with a docker-compose configuration for that which is under, the initial default location is from the root of the project:
src/main/docker/postgresql.yml so let's start it, from the initial folder on the generated project:
docker-compose -f src/main/docker/postgresql.yml up -d, after running the command wait a few seconds and check if PostgreSQL is indeed started:
docker ps you should see a running PostgreSQL database running:
If you're running a monolithic version of Jhipster app, this should be enough to run the actual Springboot application, in case you're running the Gateway version as I did you will also need to have the service registry running before starting the application, there is also a docker-compose available for that, run:
docker-compose -f src/main/docker/jhipster-registry.yml up -d, wait a few seconds and check again
docker ps, you should now see the registry also running + Postgres.
Now that Postgres and the registry are running, let's run the application. from the initial project folder:
Being the first time we run the project, it will build, download dependencies and should start after some time, you should then see something like this:
Application 'CustomJhipster' is running! Access URLs: Local: http://localhost:8080/ External: http://127.0.1.1:8080/ Profile(s): [dev, swagger]
Navigate in your browser to http://localhost:8080 and login in the generated app with admin/admin initial default credentials.
Navigate around to see the default generated application and what it offers, its a lot that you get out of the box.
The generated application from this post is available at Github, you can clone it with:
git clone firstname.lastname@example.org:stockgeeks/jhipster-custom.git && git checkout tags/v1.0, after the project is cloned and the tagged version checked out by the previous command you should have the exactly version I generated while creating this post.
There are many ways to evolve your generated Jhipster application, they provide nice tooling and
CLI for it and you can also use the Angular CLI for front end among many other possibilities. I use it as a kickstart for my side projects but I have many personal preferences and from the initial generated application I usually do a lot of small customization to fit my preferred development setup so I plan to cover in the next blog posts where I will explain my personal customizations including(random order and not limited to):
- Docker Compose setup
- Replacing shipped database management from Liquibase to Flyway.
- Modularizing the generated app.
- Separating the Front End to its own module and build.
- Gitlab pipeline to build the application.
- Setup to deploy the application to the cloud.
- Cleaning up the project configurations that I don't use to simplify it.
Stay tuned. Feedback is highly appreciated.
Git repo with the generated initial Jhipster project from this post
Photo by David Rangel on Unsplash
That's it for now, hope you liked it. Keep learning!
Follow me on Twitter