spring_reference/VII. Spring Boot CLI/55.5. Initialize a new proj...

1.7 KiB
Raw Blame History

55.5. 初始化新工程

init命令允许你使用start.spring.io在不离开shell的情况下创建一个新的项目。例如

$ spring init --dependencies=web,data-jpa my-project
Using service at https://start.spring.io
Project extracted to '/Users/developer/example/my-project'

这创建了一个my-project目录它是一个基本Maven且依赖spring-boot-starter-webspring-boot-starter-data-jpa的项目。你可以使用--list参数列出该服务的能力。

$ spring init --list
=======================================
Capabilities of https://start.spring.io
=======================================

Available dependencies:
-----------------------
actuator - Actuator: Production ready features to help you monitor and manage your application
...
web - Web: Support for full-stack web development, including Tomcat and spring-webmvc
websocket - Websocket: Support for WebSocket development
ws - WS: Support for Spring Web Services

Available project types:
------------------------
gradle-build -  Gradle Config [format:build, build:gradle]
gradle-project -  Gradle Project [format:project, build:gradle]
maven-build -  Maven POM [format:build, build:maven]
maven-project -  Maven Project [format:project, build:maven] (default)

...

init命令支持很多选项,查看help输出可以获得更多详情。例如下面的命令创建一个使用Java8和war打包的gradle项目

$ spring init --build=gradle --java-version=1.8 --dependencies=websocket --packaging=war sample-app.zip
Using service at https://start.spring.io
Content saved to 'sample-app.zip'