【Java,Windows】命令行初始化 SpringBoot项目

先记录,后整理

安装 spring-boot-cli
PS> choco find spring

Output:

Chocolatey v0.11.1
vscode-spring-initializr 0.7.0 [Approved]
spring-boot-cli 2.2.4 [Approved]
vscode-spring-boot-dashboard 0.2.0 [Approved]
SpringToolSuite 3.9.6 [Approved] Downloads cached for licensed users
vscode-spring-boot 1.28.0 [Approved]
jhipster 5.8.2 [Approved]
mailspring 1.3.0 [Approved] Downloads cached for licensed users
camunda-bpm-tomcat 7.11.0 [Approved] Downloads cached for licensed users - Possibly broken for FOSS users (due to original download location changes by vendor)
boxes.portable 2.1.1 [Approved]
uhe-twangstrom 1.0.12092 [Approved]

管理员权限下的 CMD/PowerShell/WindowsTerminal 安装 spring-boot-cli:

PS> choco install spring-boot-cli
PS> choco install spring-boot-cli --version <指定版本[例如: 2.2.3]>

PS: 下面的所有命令都是在 spring-boot-cli 2.2.4 下进行的。


spring命令:

  通过上面的安装后,我们有了 spring 命令。
&esmp;&esmp;可以通过下面命令查看命令帮助:

PS> spring help
查看对应的命令帮助:
PS> spring help init

Output:

spring init - Initialize a new project using Spring Initializr (start.spring.io)

usage: spring init [options] [location]

Option                       Description
------                       -----------
-a, --artifactId <String>    Project coordinates; infer archive name (for
                               example 'test')
-b, --boot-version <String>  Spring Boot version (for example '1.2.0.RELEASE')
--build <String>             Build system to use (for example 'maven' or
                               'gradle') (default: maven)
-d, --dependencies <String>  Comma-separated list of dependency identifiers to
                               include in the generated project
--description <String>       Project description
-f, --force                  Force overwrite of existing files
--format <String>            Format of the generated content (for example
                               'build' for a build file, 'project' for a
                               project archive) (default: project)
-g, --groupId <String>       Project coordinates (for example 'org.test')
-j, --java-version <String>  Language level (for example '1.8')
-l, --language <String>      Programming language  (for example 'java')
--list                       List the capabilities of the service. Use it to
                               discover the dependencies and the types that are
                               available
-n, --name <String>          Project name; infer application name
-p, --packaging <String>     Project packaging (for example 'jar')
--package-name <String>      Package name
-t, --type <String>          Project type. Not normally needed if you use --
                               build and/or --format. Check the capabilities of
                               the service (--list) for more details
--target <String>            URL of the service to use (default: https://start.
                               spring.io)
-v, --version <String>       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
spring init 命令详解:
PS> spring init -d=web,jpa --build=gradle -j=1.8 -p=war 
-v=0.0.1 -l=java -b=2.5.5  -g=com.example -a=test --package-name=test
# -d/--dependencies: 使用的依赖有哪些,使用 `,` 号分隔,如上: web,jpa. 
# --build: 使用的构建文件,默认是 maven; 如上是使用了 gradle.
# -l/--language: 指定是 java 还是 Kotlin,Groovy; 默认是 Java.
# -j/--java-verion: 指定 java 版本.
# -p: 指定打包后生成的类型,例如: jar, war.
# --package-name: 指定包名.
# -g/--groupId: 指定 project 的 groupId.
# -a/-artifactId: 指定 project 的 artifactId.
# -v/--version: 指定 project 的版本.
# -n/--name: project 名称.
# -b/--boot-version: 指定 spring-boot 版本

PS:
1.

# 在当前路径下生成 SpringBoot 项目.
PS> spring init 

# 生成一个打包了的 SpringBoot 项目.
PS> spring init my-app.zip

# 指定 SpringBoot 项目的生成位置.
PS> spring init ./my-dir

# 注意,如果是在 PowerShell -d -g 等需要用双引号.
# 如下面,否则带有 . 和 , 的话会报错。
PS> spring init -g="com.test" -d="web,data-jpa" ./test

Refs:

查看所有可用依赖:
PS> spring init --list
# 下面输出 Parameters 是默认生成的。
# Output:
...
Parameters
+-------------+------------------------------------------+------------------------------+
| Id          | Description                              | Default value                |
+-------------+------------------------------------------+------------------------------+
| artifactId  | project coordinates (infer archive name) | demo                         |
| bootVersion | spring boot version                      | 2.5.5                        |
| description | project description                      | Demo project for Spring Boot |
| groupId     | project coordinates                      | com.example                  |
| javaVersion | language level                           | 11                           |
| language    | programming language                     | java                         |
| name        | project name (infer application name)    | demo                         |
| packageName | root package                             | com.example.demo             |
| packaging   | project packaging                        | jar                          |
| type        | project type                             | maven-project                |
| version     | project version                          | 0.0.1-SNAPSHOT               |
+-------------+------------------------------------------+------------------------------+

附件:

依赖日志查看输出文件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值