Spring Boot CLI
SpringBoot提供的控制台命令工具,可用於快速搭建基於Spring的原型。它支援運行Groovy指令碼,這也就意味著你可以使用類似Java的文法,但不用寫很多的模板代碼。
下載地址:
https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/1.4.7.RELEASE/spring-boot-cli-1.4.7.RELEASE-bin.zip
https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/1.4.7.RELEASE/spring-boot-cli-1.4.7.RELEASE-bin.tar.gz 下載解壓即可。 該目錄下有一個install.txt,裡面有些簡單的安裝說明, 設定環境變數,添加…\spring-1.4.7.RELEASE\bin該路徑。 在命令列中輸入spring –version 將顯示相關版本號碼,說明已經安裝完成。
安裝的整體流程:
下載——》配置環境變數(xxx/bin)——》完成
如果使用的是unix機器可以試試軟體開發套件SDKMAN(Software Development Kit Manager),可以用來安裝和管理多個版本的Spring Boot CLI,網站地址http://sdkman.io/ 具體不多說了,有興趣可以試一試。
以下一些命令:
//安裝SDKMAN$curl -s get.sdkman.io|bash$source "/root/.sdkman/bin/sdkman-init.sh"---------------------------//安裝springboot CLI$sdk install springboot$spring -version//找到可用的版本$sdk list springboot CLI//安裝指定版本的springboot CLI$sdk install springboot 1.4.7.RELEASE//切換版本$sdk use springboot 1.4.7.RELEASE//設定預設版本$sdk default springboot 1.4.7.RELEASE
Spring Initializr(本質上就是一個Web應用程式,產生SpringBoot項目結構)
Spring Initializr通過有以下幾種使用: 通過Web介面使用。https://start.spring.io/ 通過Spring Tool Suite使用。 通過IntelliJ IDEA使用。 通過Spring Boot CLI使用。
下面通過SpringBootCLI使用Spring Initializr進行產生SpringBoot項目
通過如下指令即可產生一個最簡單的應用程式
spring init
通過spring help init 查看如何設定參數
spring init - Initialize a new project using Spring Initializr (start.spring.io)usage: spring init [options] [location]Option Description------ ------------a, --artifactId Project coordinates; infer archive name (for example 'test')-b, --boot-version Spring Boot version (for example '1.2.0.RELEASE')--build Build system to use (for example 'maven' or 'gradle') (default: maven)-d, --dependencies Comma-separated list of dependency identifiers to include in the generated project--description Project description-f, --force Force overwrite of existing files--format Format of the generated content (for example 'build' for a build file, 'project' for a project archive) (default: project)-g, --groupId Project coordinates (for example 'org.test')-j, --java-version Language level (for example '1.8')-l, --language Programming language (for example 'java')-n, --name Project name; infer application name-p, --packaging Project packaging (for example 'jar')--package-name Package name-t, --type Project type. Not normally needed if you use --build and/or --format. Check the capabilities of the service (--list) for more details--target URL of the service to use (default: https://start.spring.io)-v, --version Project version (for example '0.0.1-SNAPSHOT')-x, --extract Extract the project archive. Inferred if a location is specified without an extensionexamples: To list all the capabilities of the service: $ spring init --list To creates a default project: $ spring init To create a web my-app.zip: $ spring init -d=web my-app.zip To create a web/data-jpa gradle project unpacked: $ spring init -d=web,jpa --build=gradle my-dir
例子:初始化一個maven,java版本為1.8,添加依賴web、jpa、security ,springboot版本1.4.7.RELEASE,包名為com.test,打包成名為myapp的jar包,artifactId為helloBoot,版本為0.0.1-SNAPSHOT
spring init --build maven -j 1.8 -dweb,jpa,security -b 1.4.7.RELEASE -g com.test -p jar myapp -a helloBoot -v 0.0.1-SNAPSHOT
項目構建成功後,在目前的目錄下即可產生名為myapp的檔案夾,即為產生的項目。
通常我們開發中使用IDEA進行構建我們的項目,不需要藉助於Spring Boot CLI,有興趣試試。