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
- 下载解压即可。
- 该目录下有一个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 extension
examples:
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,有兴趣试试。