前回のJHipsterの紹介だけをしました。
今回はJHipsterのインストール、プロジェクト生成、起動を行います。
使用するビデオ
Get Started with JHipster 7
https://www.youtube.com/watch?v=6lf64CctDAQ
テキスト:https://github.com/mraible/jhipster7-demo
事前準備
Java 11, Node.js をインストールする。
データベースも必要なのでなかったらインストールしておく。(自分の環境ではすでにMySQLが入ってた)
<<
あとで調べて分かったけど、データベース選択時に、H2 with disk-based persistenceを選べばMySQLとかをインストールしておかなくても大丈夫らしい。動画では、development database には、H2 with disk-based persistenceを選択している。(また、動画では、production databaseにはPostgreSQLを選択している)
インストール
npmでJHipsterをインストールする。
npm i -g generator-jhipster@7.0.1
プロジェクト生成
mkdir blog
cd blog
jhipster
jhipster
を実行すると、以下のような画面が表示され・・・
プロジェクト生成に関して、質問が20個ぐらい来ます。
以下、質問と回答のコピペです。
回答は、下記以外は動画と同じにしました。
項目 | 動画 | 本記事 |
---|---|---|
Production database | PostgreSQL | MySQL |
Additional languages | Spanish | Japanese |
? Which type of application would you like to create?
Monolithic application (recommended for simple projects)
? What is the base name of your application?
blog
? Do you want to make it reactive with Spring WebFlux?
No
? What is your default Java package name?
org.jhipster.blog
? Which type of authentication would you like to use?
JWT authentication (stateless, with a token)
? Which type of database would you like to use?
SQL (H2, PostgreSQL, MySQL, MariaDB, Oracle, MSSQL)
? Which production database would you like to use?
MySQL
? Which development database would you like to use?
H2 with disk-based persistence
? Which cache do you want to use? (Spring cache abstraction)
Ehcache (local cache, for a single node)
? Do you want to use Hibernate 2nd level cache?
Yes
? Would you like to use Maven or Gradle for building the backend?
Maven
? Do you want to use the JHipster Registry to configure, monitor and scale your application?
No
? Which other technologies would you like to use?
何も選択しない。
? Which Framework would you like to use for the client?
Angular
? Do you want to generate the admin UI?
Yes
? Would you like to use a Bootswatch theme (https://bootswatch.com/)?
Default JHipster
? Would you like to enable internationalization support?
Yes
? Please choose the native language of the application
English
? Please choose additional languages to install
Japanese
? Besides JUnit and Jest, which testing frameworks would you like to use?
Cypress
? Would you like to install other generators from the JHipster Marketplace?
No
ここまでやると、JHipsterのプロジェクトが生成されます。
(データベース接続の設定)
もし、development databaseをMySQLにした場合は、
src/main/resources/config/application-dev.yml
の以下の部分を自分の環境に合うように設定する。
プロジェクト生成時にMySQLを選択したら下記のコードが生成されていました。(このusernameやpasswordを自分の環境に合わせて変更)
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/blog?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true
username: root
password:
起動
./mvnw
を実行すると、ビルドして起動します。(ちょっと時間がかかります・・・)
結構待って、こんな感じの表示が出たらOKのようです。
----------------------------------------------------------
Application 'blog' is running! Access URLs:
Local: http://localhost:8080/
External: http://172.28.128.1:8080/
Profile(s): [dev, api-docs]
----------------------------------------------------------
ブラウザで http://localhost:8080/ にアクセスすると、以下の画面が表示されます。
今回のコード
Initial version of blog generated by JHipster-7.0.1
まで。
(Development database をMySQLにした場合)
DB(mysql)の設定
まで。
動画では、H2 with~を使っているので、次回からは、H2の方でやろうかなと。