Using JHipster in development

JHipster uses Spring Loaded to have "full hot reload" of your Java classes, which eliminates the need to redeploy your application. This makes developing with JHipster as enjoyable as developping with Node.js, RoR, Grails or Play!, but with the added power of Spring.

Configuration

By default, JHipster uses the "development" profile, so you don't have to configure anything.

If you want more information on the available profiles, please go the section titled "Development and Production profiles".

Running the application

As a "main" Java class

From your IDE, right-click on the "Application" class at the root of your Java package hierarchy, and run it directly. You should also be able to debug it as easily.

The application will be available on http://localhost:8080.

As a "main" Java class, with hot reloading

Warning! "Hot reload" only works correctly with Java 7, so you will have many issues if you selected the Java 8 option when generating your application

Hot reloading works thanks to a Java Agent, so you need to add the following arguments to your JVM when running the "Application" class we have used in the previous step:

-javaagent:spring_loaded/springloaded-jhipster.jar -noverify -Dspringloaded=plugins=io.github.jhipster.loaded.instrument.JHipsterLoadtimeInstrumentationPlugin

Hot reloading is very powerful, and is specific to the technologies we are using. Here is what it currently does:

  • Normal Java classes are reloaded on the fly
  • New Java classes are added to the running application
  • If your class is a Spring Bean, it is automatically "autowired" (dependency injection is triggered), and its aspects are "weaved" (transactions, security, etc... are all added automatically)
  • If your class is a Spring MVC REST Endpoint, the new URL is mapped
  • If your class is a JPA entity, the Hibernate context is automatically refreshed, the Liquibase change set is automatically generated, and the database is updated
  • If your class uses Jackson, the Jackson cache is flushed

Of course, this all works together, so if you add a new entity using our "entity" sub-generator, you have everything hot reloaded automatically:

  • The new entity is created: the class is added to the application, Hibernate is refreshed, the Liquibase changeset is added, and the database is updated
  • The Spring Data JPA repository is created and is available
  • The Spring MVC REST controller is created and the newly mapped URLs are available
  • The AngularJS code is generated and added to your index.html (and if you use grunt server your browser is automatically refreshed)

This is obviously a very complex set of features, so if you hit a bug don't hesitate to ask us. And of course, just killing the app and restarting it will make it work again :-)

As a Maven project

You can launch the Java server with Maven:

mvn spring-boot:run

The application will be available on http://localhost:8080.

If you want more information on using Maven, please go to http://maven.apache.org

Using the Java server and Grunt together

We highly recommend you use this feature, as it allows to have hot reloading of your client-side code.

You can run Grunt to work on the client-side JavaScript application:

grunt server

This should open up your Web browser, with live reload enabled, on http://localhost:9000. As soon as you modify one of your HTML/CSS/JavaScript file, your browser should refresh itself automatically.

If you have generated your application with the Sass/Compass option, your templates should also be automatically compiled into CSS.

This Grunt server has a proxy to the REST endpoints on the Java server which we just launched (on http://localhost:8080/rest), so it should be able to do live REST requests to the Java back-end.

If you want more information on using Grunt, please go to http://gruntjs.com.

Using Bower to install and update JavaScript dependencies

You can use bower normally to update your JavaScript dependencies:

bower update

Or if you want to install a new JavaScript dependency:

bower install <package>

Your JavaScript dependencies will be stored in your src/main/webapp/bower_components folder, and we believe it is a good idea to store them in your Git repository (but JHispter does not force you to do so).

If you want more information on using Bower, please go to http://bower.io.

Database updates

If you add or modify a JPA entity, you will need to update your database schema.

JHipster uses Liquibase and stores its configuration in /src/main/resources/config/liquibase/, so your development process should be:

  • Adding, modifying or removing a JPA entity
  • Adding a new "changeSet" in your db-changelog.xml file to reflect this change
  • Starting up your application

When you startup your application, the Spring Boot will update your database schema automatically using Liquibase.

If you want more information on using Liquibase, please go to http://www.liquibase.org.

Internationalization

Internationalization (or i18n) is a first-class citizen in JHipster, as we believe it should be set up at the beginning of your project (and not as an afterthought).

Usage is really easy thanks to Angular Translate, which provides a simple AngularJS directive for i18n.

For example, to add a translation to the "first name" field, just add a "translate" attribute with a key: <label translate="settings.form.firstname">First Name</label>

This key references a JSON document, which will return the translated String. AngularJS will then replace the "First Name" String with the translated version.

For example, here are the translations provided by default in JHipster for English and for French.

If you speak another language and are ready to help, feel free to send us your own translations!