在windows中安裝JHipster並創建應用

jhipster框架是目前比較流行的一個架構,它爲java服務器端開發提供了一整套的解決方案,它能夠開發和部署spring boot和anjular web 以及基於spring的微服務應用。在使用jhipster之前,需要先安裝nodejs、yeoman和Yeoman,這裏提供了兩種安裝方式:

第一種方式、傳統的安裝

1、安裝Nodejs

LTS是正式版,Current是測試版,一般開發常用的就是LTS正式版,下載完成後,一直next安裝即可,不需要設置環境變量,打開控制檯,輸入node -v出現版本號,即代表安裝成功。

安裝成功後建議設置npm鏡像加速

npm config set registry https://registry.npm.taobao.org
npm config set disturl https://npm.taobao.org/dist --global
配置後可通過下面方式來驗證是否成功
npm config get registry

2、安裝Yarn

輸入命令

npm install -g yarn react-native-cli

會自動安裝好!
安裝完yarn後同理也要設置鏡像源:

yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global

安裝完yarn之後就可以用yarn代替npm

3、安裝 Yeoman(需要全局安裝)

npm install -g yo

4、安裝JHipster

yarn global add generator-jhipster

第二種方式、通過官網給我們的一種安裝方式(包管理器安裝)

 

1、安裝Chocolatey

Chocolatey是一個Windows上的包管理器,類似於linux上的yum和 apt-get

安裝步驟,點擊這裏,官網上提供兩種方式,一種是在CMD中,一種是在PowerShell中,這裏我們使用CMD中的安裝:

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

打開CMD敲入命令,回車,就會自動安裝,並且自動配置環境變量。

2、安裝JHipster

choco install jhipster

回車以後,他只會提示Do you want to run the script?

這種提示,我們怎麼知道他要下載什麼,終於他成功的下載了所有的組件,包括我們有的(Node, Yarn, Yeoman, JDK 和 Git),如果我們電腦上有JDK 和 Git,或者不喜歡這種安裝方式的可以選擇第一種方式。

安裝成功後測試

安裝成功後,我們嘗試生成一個應用,輸入:

yo jhipster

Jhipster創建應用時的問題

你選擇的問題答案不同可能會影響到接下來的問題顯示

Q1. Which type of application would you like to create?

  • Monolithic application: 單體應用
  • Microservice application: 微服務架構的service
  • Microservice gateway: 微服務網關,爲微服務請求進行路由和安全
  • JHipster UAA server: 基於OAuth2的安全認證微服務,後文詳細解釋

Q2. What is the base name of your application?

你期望的應用的名稱

Q3. What is your default Java package name?

應用使用的默認包名,使用Yeoman的時候此值會被存儲,當下次使用的時候此值會成爲默認值,可覆寫此值

Q4. Do you want to use the JHipster Registry to configure, monitor and scale your application?

JHipster Registry是一個開源的工具,用於管理你正在運行的應用(微服務註冊中心和統一配置中心),只有在微服務架構時纔會使用

Q5. Which type of authentication would you like to use?

所有可能的答案:

  • JWT authentication: 使用JSON Web Token
  • HTTP Session Authentication:經典的基於session認證的機制
  • OAuth 2.0 / OIDC Authentication: 使用OpenID連接服務,類似於Keycloak或者Okta
  • Authentication with JHipster UAA server: 此種方式必須提前生成JHipster UAA Server (Q1的選項),它是基於OAuth2的驗證服務

Q6. Which type of database would you like to use?

你可以選擇的選項:

  • No database,僅使用微服務架構時可用
  • An SQL database: 使用關係型數據庫,將會採用Spring data jpa
  • MongoDB
  • Cassandra
  • Couchbase

Q7. Which production database would you like to use?

選擇你線上環境使用的數據庫,此選項決定src/main/resources/config/application-prod.yml的配置

Q8. Which development database would you like to use?

此選項決定你src/main/resources/config/application-dev.ymlprofile的數據庫配置項,你可以選擇:

  • H2,running in-memory,數據存儲在內存中,服務停掉數據消失
  • H2,with its data stored on disk,數據存儲在硬盤,當前只是BETA測試且不能在Windows機器上工作
  • 可以和Q7的選項一致

Q9. Do you want to use the Spring cache abstraction?

由於Spring對於Cache的允許用戶使用不同的cache實現,你可以使用chcache(本地緩存),Hazelcast(分佈式緩存)或者Infinispan(另一種分佈式緩存),此選項可以提升你的應用的性能

Q10. Do you want to use Hibernate 2nd level cache?

此選項僅當你選擇SQL數據庫並且在Q9選擇了一個緩存實現。Hibernate使用二級緩存可以更好的提升它的性能

Q11. Would you like to use Maven or Gradle?

構建此項目時將要使用的工具,Maven或者Gradle

Q12. Which other technologies would you like to use?

多選,你可以爲你的應用添加多種技術,如:

  • Social login,社交登錄功能
  • API first development using swagger-codegen:通過成swagger-codegen而使你的應用採用API優先的開發模式
  • Search engine using ElasticSearch: 對於ES的支持(Spring Data Elasticsearch)
  • Clustered HTTP sessions using Hazelcast,默認情況下,JHipster只是用Http Session來存儲Spring Security的身份驗證和授權信息。如果你在集羣中運行,使用HTTP Session將會導致一些數據一致的問題,如果你想在集羣中複製session,請選擇此項

Q13. WebSockets using Spring Websocket

啓用Websockets支持,將使用Spring WebSocket,JHipster提供了簡單的例子展示如和高效的使用

Q14. Asynchronous messages using Apache Kafka

是否使用Kafka來發布和訂閱消息

Q15. Which Framework would you like to use for the client?

選擇使用那種客戶端技術:

  • Angular version 4+
  • AngularJS version 1.x

Q16. Would you like to use the LibSass stylesheet preprocessor for your CSS?

Node-sass對於設計CSS是一個優秀的解決方案,便於高效使用,你需要運行一個Gulp服務,jhipster會自動配置

Q17. Would you like to enable internationalization support?

JHipster對於國際支持非常友好,你可以在客戶端和服務端使用。但一般對於國際化要求不多的場景,可以不選擇。

Q18. Which testing frameworks would you like to use?

默認Jhipster提供了Java單元/集成測試(spring`s Junit)和JavaScript單元測試(Karma.js),你也可以選擇:

  • Performance tests using Gatling,性能測試 Gatling
  • Behaviour tests using Cucumber,行爲測試 Cucumber
  • Angular integration tests with Protractor, angular集成測試Protractor

Q19. Would you like to install other generators from the JHipster Marketplace?

是否需要去JHipster商城安裝第三方插件模塊

原文地址:https://www.zhengjie.me/blog/433.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章