Install JHipster
Requirement: Java 8, Maven, Git, Node.js
Start with installing Yeoman
and Bower
npm install -g yo
YEOMAN, the web’s scaffording tool for webapps. Yeoman helps you to kickstart new projects, prescribing best practices and tools to help you stay productive.
npm install -g bower
BOWER, a package manager for the web. Web sites are made of lots of things — frameworks, libraries, assets, and utilities. Bower manages all these things for you. Bower keeps track of these packages in a manifest file,
bower.json
.
Then, install Grunt
and jHipster
npm install -g grunt-cli
GRUNT, the javascript task runner. With literally hundreds of plugins to choose from, you can use Grunt to automate just about anything with a minimum of effort.
npm install -g generator-jhipster
JHipster is a fully Open Source, widely used application generator. Easily create high-quality Spring Boot + AngularJS projects!
We may also need to do this.npm install
bower install
And option for installing Gulp
gulp install
Gulp is a task/build runner for development. It allows you to do a lot of stuff within your development workflow. You can compile sass files, uglify and compress js files and much more. The kicker for gulp is that its a streaming build system which doesn’t write temp files. It’s like Pipes in bash. One task flow into another. Gulp could be compared to Grunt in its usage.
New Project
Invoke jHipster
to create a new project
yo jhipster
On running this command, it needs to answer questions about how the application to be generated.
After answering all the questions, JHipster created a whole bunch of files.
Run Test
To make sure everything was good to go,
Run unit tests using grunt test
or ./mvnw test
(or mvn test
if you have maven).
Run Project
Command for running a project
./mvnw
Whenever the DB is updated, it has to clean the /target
file which including temporary and DB files to initialize the DB.
./mvnw clean
Sometimes, when the temporary files are deleted, the app may raise error like ... bean not found
. Try to avoid it by compile again
./mvnw compile
Update Jhipster
Update jHipster
npm update -g generator-jhipster
This installs the latest version of JHipster, but does nothing to upgrade the project. Then, run the following command to update the project.yo jhipster
Add Material Design
For instance,
Check bower.json
with"bootstrap-material-design": "~0.3.0"
At bottom of index.html
(src/main/webapp/index.html
), add<script>
$.material.init()
</script>
Liquibase Inconsistency
If you add or modify a JPA entity, you will need to update your DB schema.
If you have choosen to use MySQL, MariaDB or PostgreSQL in development, you can use the ./mvnw liquibase:diff
goal to automatically generate a changelog.
Entity Creation or Update
Method 1: The jhipster command used to create an entity, then in command line, answer the questions, such as field name, type, constraints and relationships to other entities.
yo jhipster:entity <name> |
Method 2: Generating an entity directily by json files.
For instance, first creating json file, e.g., UserGroup.json
, then, run yo jhipster:entity userGroup
and re-gernerate the entity.
{ |
The above json file define the entity name, fields, relationships, changelog id, whether or not to generate DTO and service layers, the style of pagination at the same time.
Method 3: Using JDL to create a whole bunch of entities based on DB schema.
Jhipster Domain Language (JDL)
The JDL is a JHipster specific domain language which describes all the entities and their relationships in a single file (or more than one) with a simple and user-friendly syntax.
Entity syntax:
entity name
is the name of the entity,field name
the name of one field of the entity,type
the JHipster supported type of the field,- and as an option
the validations for the field.
entity Author { |
relationship (OneToMany | ManyToOne | OneToOne | ManyToMany) |
For example,relationship OneToMany {
Author{book} to Book{writer(name)}
}
Command for jhipster to create entity by using JDL file
yo jhipster:import-jdl jhipster-jdl.jh |
Q & A
Delete a entity ?
Currently, jhipster has no function to delete an entity after creating it (20+ files). The best way is using version control to revert to the version before creating new entities.Make Foreign Key to be required field?
All the relationships in jhipster is a loose control. So the FK cannot set to be required when creating entities.
Ref