59.5 初始化新工程

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

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

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

  1. $ spring init --list
  2. =======================================
  3. Capabilities of https://start.spring.io
  4. =======================================
  5. Available dependencies:
  6. -----------------------
  7. actuator - Actuator: Production ready features to help you monitor and manage your application
  8. ...
  9. web - Web: Support for full-stack web development, including Tomcat and spring-webmvc
  10. websocket - Websocket: Support for WebSocket development
  11. ws - WS: Support for Spring Web Services
  12. Available project types:
  13. ------------------------
  14. gradle-build - Gradle Config [format:build, build:gradle]
  15. gradle-project - Gradle Project [format:project, build:gradle]
  16. maven-build - Maven POM [format:build, build:maven]
  17. maven-project - Maven Project [format:project, build:maven] (default)
  18. ...

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

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