This is continuation to my two previous posts. Before reading this post, please go through my previous posts at “Spring Boot Initilizr Web Interface” , “Spring Boot Initilizr With IDEs or IDE Plugins” and “Spring Boot Initilizr With Spring Boot CLI”.
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:
- Spring Boot Initilizr With Web Interface
- Spring Boot Initilizr With IDEs/IDE Plugins
- Spring Boot Initilizr With Spring Boot CLI
- Spring Boot Initilizr With ThirdParty Tools
Now we are going to discuss on “How to use some popular Third Party Tools to bootstrap Spring Applications” using “Spring Boot Initilizr With ThirdParty Tools” option.
Spring Boot Initilizr With ThirdParty Tools
We can also use the following third party tools to bootstrap Spring Boot Applications.
- CURL Tool
- HTTPie Tool
We will discuss these tools one by one with some simple examples in the following sections.
Spring Boot Example with “curl” Tool
“curl” is an open source library and command-line tool for transferring data using various protocols like FTP,FTPS,HTTP,HTTPS,SMTP,POP3,LDAP etc. We can also use this tool to bootstrap our Spring Boot applications very easily.
“curl” official website is available at : https://curl.haxx.se/
“curl” provides two projects:
- cURL Project – command line tool
- libcurl Project- library
“cURL” Tool setup
Please access the “https://curl.haxx.se/download.html” URL to download “cURL” Tool.
I have downloaded Windows 64Bit zip file as shown below
Once download is completed, We will get a zip file as shown below. Just extract this zip file to get “curl.exe” file.
In Windows, we need to set this System Variable:
PATH=D:SpringBoot;%PATH%
Here “D:SpringBoot” is my local filesystem path where “curl.exe” command is available.
“cURL” Syntax:
We need to follow the following syntax to create our Spring Boot Applications.
curl [options...] <url>
We can get all available options by executing “curl –help” command. to bootstrap a Spring Boot Application is Spring Initializr URL:: https://start.spring.io.
When we execute “curl start.spring.io” at CMD Prompt, we can see all available Parameters, List of Spring Boot “dependencies” or “capabilities” etc.
“cURL” Examples:
Example-1:- To create a Default Spring Boot Project
It creates a Default Spring Boot project with “SpringBootCurlDefaultProject.zip” name for Maven build tool in current working directory as shown below:
Example-2:- To create a Spring Boot Project with required “dependencies” and required packaging type for Gradle build tool
curl https://start.spring.io/starter.zip -d dependencies=web,data-jpa,jms,ws
-d packaging=war
-d type=gradle-project
-o SpringBootCurlWebProject.zip
Here we use “-d” option specify parameters.
“-d type=gradle-project” means creates a Gradle project. Same way we can specify for Maven Project: “-d type=maven-project” (It is default value for “type” parameter).
Example-3:- To create a Spring Boot Project with required “dependencies” and required packaging type for Maven build tool
curl https://start.spring.io/starter.zip
-d dependencies=web,jdbc,ws,cloud-aws,h2
-d packaging=war
-d type=maven-project
-o SpringBootCurlWebMavenProject.zip
Here we use “-d” option specify parameters.
“-d type=gradle-project” means creates a Gradle project. “type=maven-project” to create a Maven Project with pom.xml file(It is default value for “type” parameter).
It creates Mavenized project with Spring MVC,Spring JDBC,Spring WS,Spring Cloud with AWS, H2 Database capabilities.
Example-4:- To create a Spring Boot Project with required “dependencies” and required packaging type for Gradle build tool by specifying Java and Spring Boot Framework version.
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.
curl https://start.spring.io/starter.zip
-d dependencies=web,jdbc,ws,cloud-aws,h2
-d packaging=war
-d type=gradle-project
-d javaVersion=1.7
-d bootVersion=1.2.5.RELEASE
-o SpringBootCurlWebGradleProject.zip
Here we use “-d” option specify parameters.
- “-d javaVersion=1.7” option is used to specify Java Version like 1.7,1.8 etc.
- “-d bootVersion=1.2.5.RELEASE” option is used to specify Spring Boot Framework version like 1.2.5,1.3 etc.
- “-d type=gradle-project” means creates a Gradle project.
- “type=maven-project” to create a Maven Project with pom.xml file(It is default value for “type” parameter).
- “-d dependencies=web,jdbc,ws,cloud-aws,h2” specifies our Project Capabilities.
- “-d packaging=war” option specifies the packaging type is “war”. Default value is “jar”. It accepts “pom, jar, war, ear, rar, par”
It creates Mavenized project with Spring MVC,Spring JDBC,Spring WS,Spring Cloud with AWS, H2 Database capabilities and uses Java Varsion = 1.7 and Spring Boot Framework version = 1.2.5.RELEASE.
That’s it about “curl” tool to bootstrap a Spring Boot Applications with simple commands. We can import those projects into our Spring IDEs and can enhance them as per our project requirements.
NOTE:-
WE can refer to know the list of supported identifiers for the comma-separated list of “dependencies” at “Spring Boot Initilizr With Spring Boot CLI”.
The following section has a list of supported build options.
+-----------------+-----------------------------------------+
| Rel | Description |
+-----------------+-----------------------------------------+
| gradle-build | Generate a Gradle build file |
| gradle-project | Generate a Gradle based project archive |
| maven-build | Generate a Maven pom.xml |
| maven-project * | Generate a Maven based project archive |
+-----------------+-----------------------------------------+
Default build parameter value is “maven-project”
The URI templates take a set of parameters to customize the result of a request to the linked resource..
+-----------------+------------------------------------------+------------------------------+
| Parameter | Description | Default value |
+-----------------+------------------------------------------+------------------------------+
| applicationName | application name | DemoApplication |
| artifactId | project coordinates (infer archive name) | demo |
| baseDir | base directory to create in the archive | no base dir |
| bootVersion | spring boot version | 1.2.5.RELEASE |
| dependencies | dependency identifiers (comma-separated) | none |
| description | project description | Demo project for Spring Boot |
| groupId | project coordinates | org.test |
| javaVersion | language level | 1.8 |
| language | programming language | java |
| name | project name (infer application name) | demo |
| packageName | root package | demo |
| packaging | project packaging | jar |
| type | project type | maven-project |
| version | project version | 0.0.1-SNAPSHOT |
+-----------------+------------------------------------------+------------------------------+
Spring Boot Example with “HTTPie” Tool
Like CURL tool, HTTPie is a command line HTTP client to bootstrap a Spring Boot applications with simple commands. It is a human-friendly JSON based tool. It is mainly used for testing, debugging and interacting with HTTP Web Services or Web Servers.
Httpie official website: https://github.com/jkbrzt/httpie
“HTTPie” Tool Setup
I have installed Python 2.7 as shown below. Installation is very easy with zip file. If you use Windows Installer then just follow default settings to install it.
-
- Download “get-pip.py” from “https://pip.pypa.io/en/latest/installing.html#install-pip”
Just Mouse right click and save as to your required filesystem path:
-
- Install “pip” by using the following command
python get-pip.py
-
- Install “httpie” tool by using the following command
python -m pip install --upgrade httpie
“HTTPie” Examples
Example-1:- To create a Default Spring Boot Project
python -m httpie https://start.spring.io/starter.zip -d
It creates a new Spring Boot Project with default settings like: create project filename is “demo.zip”, Build tool is “Maven”. It takes default Java Version and Spring Boot Framework version from System Variables.
Example-2:- To create a Spring Boot WebAppilcation(war) Project With required dependencies for Gradle build tool
python -m httpie https://start.spring.io/starter.zip
dependencies==web,data-jpa,jms,ws
type==gradle-project
packaging==war
-d
It creates a Gradle project with Spring MVC,Spring DATA JPA,Spring JMS,Spring WS Capabilities.
NOTE:-Here we should observe that we need to use double equal symbols like “==” between parameter or option names and values.
We can refer “Curl tool” section to know the list of supported “dependencies”, “parameters” and build tool options. Both HTTPIE and Curl tools share same options and parameters.
That’s it all about “Spring Boot Initilizr With Thard Party Tools”.
Please drop me a comment if you face any issues or have any suggestions.