This is continuation to my two previous posts. Before reading this post, please go through my previous posts at “Spring Boot Initilizr Web Interface” and “Spring Boot Initilizr With IDEs or IDE Plugins”.

Spring Boot Initilizr is used to quick start new Spring Boot Maven/Gradle projects within no time. It generates initial project structure and build scripts to reduce Development time.

As we discussed in my previous post, Spring Boot Initilizr is available in the following forms:

  1. Spring Boot Initilizr With Web Interface
  2. Spring Boot Initilizr With IDEs/IDE Plugins
  3. Spring Boot Initilizr With Spring Boot CLI
  4. Spring Boot Initilizr With ThirdParty Tools

Now we are going to discuss on How to bootstrap Spring Applications using “Spring Boot Initilizr With Spring Boot CLI” option.

Spring Boot Initilizr With Spring Boot CLI

Please go through this post first “Spring Boot CLI Basics” to setup Spring Boot CLI software. Spring Boot CLI provides a “spring init” command to bootstrap Spring Applications.

I have downloaded Spring Boot CLI zip from “https://start.spring.io” and installed this Software at “D:spring-boot-cli-1.2.3.RELEASE”.

Set the following System Variable:


PATH=D:spring-boot-cli-1.2.3.RELEASEbin;%PATH%

“spring init” command

The “spring init” command is easy to use command from Spring Boot CLI Component. It uses “Spring Initilizr Service” hosted at “https://start.spring.io” (default, we can specify the the target URL also. We will discuss this in next section.) to bootstrap Spring or Spring Boot Applications by using Spring Boot CLI component.

“spring init” syntax


spring init [options] [location]

Here “options” are command options and “location” is specified our file system location to create new Spring Boot Project. We will discuss command options one by one in detail soon.

Use “spring help init” command to see all available “spring init” command options as shown below.


spring help init
springboot-init-cli-help-450x391

The “spring init” command examples

Now we will explore “spring init” command options one by one with some suitable examples. Open CMD(Command Prompt) at your IDE Workspace(My Workspace is at D:RamWorkspacesSpringSTSBootWorkspace2) and execute the following examples.

Example-1:- To create Spring Boot project with default settings:


spring init
springboot-init-cli-help-450x391

It creates new Spring Boot Project zip file as “demo.zip” at current working directory with default settings.

NOTE:- “spring init” Default settings:

    1. Default Build tool is “maven”.
    2. Default Spring Initilizr service target URL: https://start.spring.io
    3. Default project name: “demo”
    4. Default maven type: “jar”
    5. Default Spring Boot dependencies added to build script file:

<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-test</artifactId>
		<scope>test</scope>
	</dependency>
</dependencies>
    1. Default Maven artifacts:

    <groupId>org.test</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>demo</name>

Example-2:- To create Spring Boot Project with required Dependencies and Project name


spring init -d=web,data-jpa,jms,ws SpringMVCMavenToolProject.zip

It creates a packed Spring Boot WebApplication with JPA,JMS and WS capabilities.

springboot-init-cli-help-450x391

Here “-d” option means we can list out all required capabilities with comma separated values.
“SpringMVCMavenToolProject.zip” is a Project name and zip file created with that name in the current working directory.

Example-3:-To create Spring Boot Project with required Dependencies and Project name for Gradle Build Tool.


spring init -d=web,data-jpa,jms,ws --build=gradle -p=war SpringMVCGradleToolProject

It creates a unpacked Spring Boot WebApplication with JPA,JMS and WS capabilities for Gradle build tool.

  • “-d” option means we can list out all required capabilities with comma separated values.
  • “–build” option specifies required build tool. It accepts two values: maven(Default) and gradle.
  • “SpringMVCGradleToolProject” is a Project name created in the current working directory.
  • “-p” or “–packaging” option specifies the packaging type. Default value is “jar”.

Example-4:-To create Spring Boot Project with required Dependencies and Project name for Maven Build Tool.


spring init -d=web,jdbc,ws,cloud-aws,h2 --build=maven
            --packaging=war SpringMVCMavenToolProject.zip

It creates a packed Spring Boot WebApplication with JDBC,AWS Cloud and WS capabilities for Maven build tool.

  • “-d” option means we can list out all required capabilities with comma separated values.
  • “–build” option specifies required build tool. It accepts two values: maven(Default) and gradle.
  • “SpringMVCMavenToolProject” is a Project name created in the current working directory.
  • “-p” or “–packaging” option specifies the packaging type. Default value is “jar”. It accepts “pom, jar, war, ear, rar, par”

Example-5:-To create Spring Boot Project with required Dependencies and Project name for Maven Build Tool with specified Spring Boot and Java Versions.

By default, “spring init” command will pickup “System Variables” and take appropriate Spring Boot and Java Versions. However it is possible to specify Spring Boot and Java Versions.

My Windows system is configured with Java Version = 1.8 and Spring Boot version = 1.2.3.RELEASE. However I would like to change them in creating new Spring Boot project as shown below.


spring init -d=web,jdbc,ws,cloud-aws,h2 --build=maven
            --java-version=1.7
            --boot-version=1.2.5.RELEASE
            -packaging=war SpringMVCMavenToolProject.zip

It creates a packed Spring Boot WebApplication with JDBC,AWS Cloud and WS capabilities for Maven build tool with Java 1.7 and Spring Boot 1.2.5.RELEASE.

  • “-j” or “–java-version” option is used to specify Java Version like 1.7,1.8 etc.
  • “-b” or “–boot-version” option is used to specify Spring Boot Framework version like 1.2.5.RELEASE,1.3.0.M1 etc.
  • “-d” option means we can list out all required capabilities with comma separated values.
  • “–build” option specifies required build tool. It accepts two values: maven(Default) and gradle.
  • “SpringMVCMavenToolProject” is a Project name created in the current working directory.
  • “-p” or “–packaging” option specifies the packaging type. Default value is “jar”. It accepts “pom, jar, war, ear, rar, par”

NOTE:-
When we execute “spring init” command, we can observe the following message saying that it is going to connect “Spring Boot Initilizr Default Service”.


Using service at https://start.spring.io

In the same way, we can use other “spring init” options to explore them. For example, “–force” to force update already existing same project name with updates to avoid errors.

NOTE:-
We can extract those zip files created using “spring init” command and import these projects into our favorite Spring IDEs(For example:- Spring STS Suite) and continue to develop our project related requirements.

We will develop some applications by using these Spring Boot projects to enhance some functionality in my coming posts.

The following section has a list of supported build options.


+--------+----------------------------------------------------------------------+
| Id     | Description                                                          |
+--------+----------------------------------------------------------------------+
| maven  | Creates a Maven project with pom.xml file for Maven build tool       |
| gradle | Creates a Maven project with build.gradle file for Gradle build tool |
+-------------------------------------------------------------------------------+

Default build parameter value is “maven”

The following section has a list of supported identifiers for the comma-separated list of “dependencies”.


+-------------------------+-----------------------------------------------------------------------------------------------+------------------+
| Id                      | Description                                                                                   | Required version |
+-------------------------+-----------------------------------------------------------------------------------------------+------------------+
| actuator                | Production ready features to help you monitor and manage your application                     |                  |
| amqp                    | Support for the Advanced Message Queuing Protocol via spring-rabbit                           |                  |
| aop                     | Support for aspect-oriented programming including spring-aop and AspectJ                      |                  |
| batch                   | Support for Spring Batch including HSQLDB database                                            |                  |
| cache                   | Support for Spring's Cache abstraction                                                        | >= 1.3.0.M1      |
| cloud-aws               | Support for spring-cloud-aws                                                                  | >= 1.2.3.RELEASE |
| cloud-aws-jdbc          | Support for spring-cloud-aws-jdbc                                                             | >= 1.2.3.RELEASE |
| cloud-aws-messaging     | Support for spring-cloud-aws-messaging                                                        | >= 1.2.3.RELEASE |
| cloud-bus-amqp          | Support for spring-cloud-bus-amqp                                                             | >= 1.2.3.RELEASE |
| cloud-config-client     | Support for spring-cloud-config Client                                                        | >= 1.2.3.RELEASE |
| cloud-config-server     | Support for spring-cloud-config Server                                                        | >= 1.2.3.RELEASE |
| cloud-connectors        | Simplifies connecting to services in cloud platforms                                          | >= 1.2.0.RELEASE |
| cloud-eureka            | Support for spring-cloud-netflix Eureka                                                       | >= 1.2.3.RELEASE |
| cloud-eureka-server     | Support for spring-cloud-netflix Eureka Server                                                | >= 1.2.3.RELEASE |
| cloud-feign             | Support for spring-cloud-netflix Feign                                                        | >= 1.2.3.RELEASE |
| cloud-hystrix           | Support for spring-cloud-netflix Hystrix                                                      | >= 1.2.3.RELEASE |
| cloud-hystrix-dashboard | Support for spring-cloud-netflix Hystrix Dashboard                                            | >= 1.2.3.RELEASE |
| cloud-oauth2            | Support for spring-cloud-security OAuth2                                                      | >= 1.2.3.RELEASE |
| cloud-ribbon            | Support for spring-cloud-netflix Ribbon                                                       | >= 1.2.3.RELEASE |
| cloud-security          | Support for spring-cloud-security                                                             | >= 1.2.3.RELEASE |
| cloud-starter           | Support for spring-cloud-context (e.g. Bootstrap context and @RefreshScope)                   | >= 1.2.3.RELEASE |
| cloud-turbine           | Support for spring-cloud-netflix Turbine                                                      | >= 1.2.3.RELEASE |
| cloud-turbine-amqp      | Support for spring-cloud-netflix Turbine AMQP                                                 | >= 1.2.3.RELEASE |
| cloud-zuul              | Support for spring-cloud-netflix Zuul                                                         | >= 1.2.3.RELEASE |
| data-elasticsearch      | Support for the Elasticsearch search and analytics engine including spring-data-elasticsearch |                  |
| data-gemfire            | Support for the GemFire distributed data store including spring-data-gemfire                  |                  |
| data-jpa                | Support for the Java Persistence API including spring-data-jpa, spring-orm and Hibernate      |                  |
| data-mongodb            | Support for the MongoDB NoSQL Database, including spring-data-mongodb                         |                  |
| data-rest               | Support for exposing Spring Data repositories over REST via spring-data-rest-webmvc           |                  |
| data-solr               | Support for the Apache Solr search platform, including spring-data-solr                       |                  |
| derby                   | Support for the Apache Derby database (with embedded support)                                 | >= 1.2.2.RELEASE |
| devtools                | Support for Spring Boot Development Tools.                                                    | >= 1.3.0.M1      |
| freemarker              | Support for the FreeMarker templating engine                                                  |                  |
| groovy-templates        | Support for the Groovy templating engine                                                      |                  |
| h2                      | Support for the H2 database (with embedded support)                                           |                  |
| hateoas                 | Support for HATEOAS-based RESTful services                                                    | >= 1.2.2.RELEASE |
| hornetq                 | Support for Java Message Service API via HornetQ                                              |                  |
| hsql                    | Support for the HSQLDB database (with embedded support)                                       |                  |
| integration             | Support for common spring-integration modules                                                 |                  |
| jdbc                    | Support for JDBC databases                                                                    |                  |
| jersey                  | Support for the Jersey RESTful Web Services framework                                         | >= 1.2.0.RELEASE |
| jta-atomikos            | Support for JTA distributed transactions via Atomikos                                         | >= 1.2.0.M1      |
| jta-bitronix            | Support for JTA distributed transactions via Bitronix                                         | >= 1.2.0.M1      |
| mail                    | Support for javax.mail                                                                        | >= 1.2.0.RC1     |
| mobile                  | Support for spring-mobile                                                                     |                  |
| mustache                | Support for the Mustache templating engine                                                    | >= 1.2.2.RELEASE |
| mysql                   | Support for the MySQL jdbc driver                                                             |                  |
| postgresql              | Support for the PostgreSQL jdbc driver                                                        |                  |
| redis                   | Support for the REDIS key-value data store, including spring-redis                            |                  |
| remote-shell            | Support for CRaSH                                                                             |                  |
| security                | Support for spring-security                                                                   |                  |
| social-facebook         | Support for spring-social-facebook                                                            |                  |
| social-linkedin         | Support for spring-social-linkedin                                                            |                  |
| social-twitter          | Support for spring-social-twitter                                                             |                  |
| thymeleaf               | Support for the Thymeleaf templating engine, including integration with Spring                |                  |
| vaadin                  | Support for Vaadin                                                                            |                  |
| velocity                | Support for the Velocity templating engine                                                    |                  |
| web                     | Support for full-stack web development, including Tomcat and spring-webmvc                    |                  |
| websocket               | Support for websocket development with Tomcat                                                 |                  |
| ws                      | Support for Spring Web Services                                                               |                  |
+-------------------------+-----------------------------------------------------------------------------------------------+------------------+

From this list, we have already used “web,data-jpa,jms,ws” in our examples. Please also try to use other capabilities or dependencies to develop some examples. We will use other dependencies to explore them in my coming posts.

You can read remaining “ThirdParty Tools” option in my coming post at “Spring Boot Initilizr With ThirdParty Tools“.

That’s it all about “Spring Boot Initilizr With Spring Boot CLI”.

Please drop me a comment if you face any issues or have any suggestions.

By admin

Leave a Reply

%d bloggers like this: