JHipster Crash Course
Tags: java, microservices, springboot, jhipster
Published: 2020-02-08 13:42:07

In this post, I will cover and guide you through the necessary steps to generate a [JHipster](https://www.jhipster.tech/) 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](https://www.jhipster.tech/api-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](https://www.jhipster.tech) 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](https://www.jhipster.tech/installation/) 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](https://dev.to/thegroo/basic-setup-for-some-tutorials-51m) including [docker](https://dev.to/thegroo/one-to-run-them-all-1mg6),  [java](https://dev.to/thegroo/install-and-manage-multiple-java-versions-on-linux-using-alternatives-5e93) or getting your initial [overview of Springboot](https://dev.to/thegroo/spring-boot-crash-course-21nm) 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`

2. 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`

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

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

5. Define a java package name: `io.stockgeeks`

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

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

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

9. Cache options pick: `Yes, with the Ehcache implementation`.

10. Use hibernate 2nd level cache: `Yes`

11. Maven or Gradle: `Maven`

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

13. Front End framework: `Angular` 

14. Bootswatch theme: `Default JHipster`

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

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

17. 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](https://dev-to-uploads.s3.amazonaws.com/i/m7i9im30boc4hp3fvhqc.png)

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]


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

![Jhipster initial app](https://dev-to-uploads.s3.amazonaws.com/i/38pisipfuq4vqis6vzq2.png)

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](https://www.jhipster.tech/)


Photo by [David Rangel on Unsplash](https://unsplash.com/photos/4m7gmLNr3M0)


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

Follow me on [Twitter](https://twitter.com/thegroo)