DEV Community

Cover image for JHipster Crash Course
Marcos Maia
Marcos Maia

Posted on • Updated on

JHipster Crash Course

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.

Generate a Jhipster project

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.

I also have some posts which you can follow if you want to have a basic setup including docker, java or getting your initial overview of Springboot applications.

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.

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

  1. Start the jhipster generator in the command line:

jhipster

You will be presented with a list of options to pick, choose Microservice gateway or Monolithic application

  1. Next step is to choose a base name for your application: CustomJhipster

  2. Now you will be prompted to select a port, leave the default: 8080

  3. Define a java package name: io.stockgeeks

  4. 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 Registry which uses Eureka with Spring Cloud Config support.

  5. Type of authentication: JWT authentication (stateless, with a token).

  6. Database, pick: SQL and then select Postgres and Postgres again in the development database option.

  7. Cache options pick: Yes, with the Ehcache implementation.

  8. Use hibernate 2nd level cache: Yes

  9. Maven or Gradle: Maven

  10. Other technologies: None, just hit enter without selecting any for now.

  11. Front End framework: Angular

  12. Bootswatch theme: Default JHipster

  13. Internationalization support: No lets stick to Englis for the series.

  14. Testing Frameworks: None just hit enter and skip it, JUnit is already there in the generated project.

  15. Other generators from Marketplace: No

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:

Running Postgres

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:

mvn spring-boot:run

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:

Started CustomJhipsterApp in 8.199 seconds (JVM running for 8.607)

Application 'CustomJhipster' is running! Access URLs:
Local:      http://localhost:8080/
External:   http://127.0.1.1:8080/
Profile(s):     [dev, swagger]
Enter fullscreen mode Exit fullscreen mode

Navigate in your browser to http://localhost:8080 and login in the generated app with admin/admin initial default credentials.

Jhipster initial app

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 git@github.com: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.

Stay tuned. Feedback is highly appreciated.

References

JHipster Website

Photo by David Rangel on Unsplash

That's it for now, hope you liked it. Keep learning!

Follow me on Twitter

Top comments (4)

Collapse
 
rophilogene profile image
Romaric P.

hey @marcos , I think you will like this quick article and video on how to deploy JHipster publicly in 15 seconds. Here is the deployed JHipster sample app > sw21p7e5xmbowrpi-main-gtw.qovery.io

Collapse
 
thegroo profile image
Marcos Maia

Hi Romaric,

yes, I will definitely take a look. Thank you!

Collapse
 
jamilxt profile image
Jamilur Rahman

seems like the link is broken. :(

Collapse
 
jamilxt profile image
Jamilur Rahman • Edited

Thank you. When will be the next part published?