[JAVA] Create a Spring Boot app development project with the cURL + tar command

When creating a new Spring Boot app, I think that many people create development projects by one of the following methods.

You can search for Specifiable Dependent Artifs using the Web UI or IDE wizard, and you can easily create a development project simply by specifying a value in the input form and clicking. This is very convenient and I love it, but sometimes I find the UI operation itself to be a hassle.

In such a case, it's CLI. Spring Boot also supports the method of creating a development project using the commands provided by Spring Boot, but this time I will show you how to use the curl and tar commands.

Create a project for a standalone app

You can create a development project for a stand-alone application (= non-WEB) by executing the following command.

$ curl -s https://start.spring.io/starter.tgz -d baseDir=demo | tar -xzvf -
x demo/mvnw
x demo/
x demo/.mvn/
x demo/.mvn/wrapper/
x demo/src/
x demo/src/main/
x demo/src/main/java/
x demo/src/main/java/com/
x demo/src/main/java/com/example/
x demo/src/main/resources/
x demo/src/test/
x demo/src/test/java/
x demo/src/test/java/com/
x demo/src/test/java/com/example/
x demo/.gitignore
x demo/.mvn/wrapper/maven-wrapper.jar
x demo/.mvn/wrapper/maven-wrapper.properties
x demo/mvnw.cmd
x demo/pom.xml
x demo/src/main/java/com/example/DemoApplication.java
x demo/src/main/resources/application.properties
x demo/src/test/java/com/example/DemoApplicationTests.java

Directory structure


$ tree demo
demo
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── example
    │   │           └── DemoApplication.java
    │   └── resources
    │       └── application.properties
    └── test
        └── java
            └── com
                └── example
                    └── DemoApplicationTests.java

Try to build.

$ cd demo
$ ./mvnw clean package

Try to run it.

$ java -jar target/demo-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.3.RELEASE)

2017-01-03 15:38:28.749  INFO 31974 --- [           main] com.example.DemoApplication              : Starting DemoApplication v0.0.1-SNAPSHOT on Kazuki-no-MacBook-Pro.local with PID 31974 (/usr/local/apps/demo/target/demo-0.0.1-SNAPSHOT.jar started by shimizukazuki in /usr/local/apps/demo)
2017-01-03 15:38:28.751  INFO 31974 --- [           main] com.example.DemoApplication              : No active profile set, falling back to default profiles: default
2017-01-03 15:38:28.794  INFO 31974 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5b37e0d2: startup date [Tue Jan 03 15:38:28 JST 2017]; root of context hierarchy
2017-01-03 15:38:29.312  INFO 31974 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-01-03 15:38:29.323  INFO 31974 --- [           main] com.example.DemoApplication              : Started DemoApplication in 0.843 seconds (JVM running for 1.151)
2017-01-03 15:38:29.324  INFO 31974 --- [       Thread-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@5b37e0d2: startup date [Tue Jan 03 15:38:28 JST 2017]; root of context hierarchy
2017-01-03 15:38:29.325  INFO 31974 --- [       Thread-1] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown

:clap: :clap: :clap:

Create a project for a web application

You can create a development project for a web application by executing the following command (specify the web for dependencies).

$ curl -s https://start.spring.io/starter.tgz -d name=web-demo -d artifactId=web-demo -d dependencies=web -d baseDir=web-demo | tar -xzvf -
x web-demo/mvnw
x web-demo/
x web-demo/.mvn/
x web-demo/.mvn/wrapper/
x web-demo/src/
x web-demo/src/main/
x web-demo/src/main/java/
x web-demo/src/main/java/com/
x web-demo/src/main/java/com/example/
x web-demo/src/main/resources/
x web-demo/src/main/resources/static/
x web-demo/src/main/resources/templates/
x web-demo/src/test/
x web-demo/src/test/java/
x web-demo/src/test/java/com/
x web-demo/src/test/java/com/example/
x web-demo/.gitignore
x web-demo/.mvn/wrapper/maven-wrapper.jar
x web-demo/.mvn/wrapper/maven-wrapper.properties
x web-demo/mvnw.cmd
x web-demo/pom.xml
x web-demo/src/main/java/com/example/WebDemoApplication.java
x web-demo/src/main/resources/application.properties
x web-demo/src/test/java/com/example/WebDemoApplicationTests.java

Directory structure


$ tree web-demo
web-demo
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── example
    │   │           └── WebDemoApplication.java
    │   └── resources
    │       ├── application.properties
    │       ├── static
    │       └── templates
    └── test
        └── java
            └── com
                └── example
                    └── WebDemoApplicationTests.java

Try to build.

$ cd web-demo
$ ./mvnw clean package

Try to run it.

$ java -jar target/web-demo-0.0.1-SNAPSHOT.jar

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.3.RELEASE)

2017-01-03 15:48:49.606  INFO 32190 --- [           main] com.example.WebDemoApplication           : Starting WebDemoApplication v0.0.1-SNAPSHOT on Kazuki-no-MacBook-Pro.local with PID 32190 (/usr/local/apps/web-demo/target/web-demo-0.0.1-SNAPSHOT.jar started by shimizukazuki in /usr/local/apps/web-demo)
2017-01-03 15:48:49.608  INFO 32190 --- [           main] com.example.WebDemoApplication           : No active profile set, falling back to default profiles: default
2017-01-03 15:48:49.658  INFO 32190 --- [           main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4bf558aa: startup date [Tue Jan 03 15:48:49 JST 2017]; root of context hierarchy
2017-01-03 15:48:50.658  INFO 32190 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2017-01-03 15:48:50.670  INFO 32190 --- [           main] o.apache.catalina.core.StandardService   : Starting service Tomcat
2017-01-03 15:48:50.671  INFO 32190 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.6
2017-01-03 15:48:50.744  INFO 32190 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2017-01-03 15:48:50.744  INFO 32190 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1089 ms
2017-01-03 15:48:50.855  INFO 32190 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2017-01-03 15:48:50.858  INFO 32190 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2017-01-03 15:48:50.858  INFO 32190 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2017-01-03 15:48:50.858  INFO 32190 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2017-01-03 15:48:50.858  INFO 32190 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2017-01-03 15:48:51.071  INFO 32190 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@4bf558aa: startup date [Tue Jan 03 15:48:49 JST 2017]; root of context hierarchy
2017-01-03 15:48:51.123  INFO 32190 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2017-01-03 15:48:51.124  INFO 32190 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2017-01-03 15:48:51.147  INFO 32190 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-01-03 15:48:51.147  INFO 32190 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-01-03 15:48:51.173  INFO 32190 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-01-03 15:48:51.282  INFO 32190 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-01-03 15:48:51.335  INFO 32190 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-01-03 15:48:51.338  INFO 32190 --- [           main] com.example.WebDemoApplication           : Started WebDemoApplication in 2.123 seconds (JVM running for 2.45)

Try to access the started Tomcat.

$ curl http://localhost:8080/
{"timestamp":1483426201099,"status":404,"error":"Not Found","message":"No message available","path":"/"}

I haven't created an endpoint, so it's correct to get a 404 Not Found error.

:clap: :clap: :clap:

For more information···

Read the Spring Initializr GitHub README.

Summary

If you have decided what to make in advance (for example, in the case of the procedure when setting up the development environment) ... Develop with one liner (= copy command) using CLI instead of GUI It is efficient to follow the procedure for creating a project.

Recommended Posts

Create a Spring Boot app development project with the cURL + tar command
Create a simple search app with Spring Boot
Create a Spring Boot development environment with docker
Create an app with Spring Boot 2
Create an app with Spring Boot
Create a Maven project with a command
Create a jar file with the command
Create a website with Spring Boot + Gradle (jdk1.8.x)
Create a web api server with spring boot
Create a portfolio app using Java and Spring Boot
How to create a Spring Boot project in IntelliJ
[Spring Boot] How to create a project (for beginners)
Create Restapi with Spring Boot ((1) Until Run of App)
Create a simple demo site with Spring Security with Spring Boot 2.1
Create microservices with Spring Boot
A story packed with the basics of Spring Boot (solved)
Create a Hello World web app with Spring framework + Jetty
Hot deploy with Spring Boot development
Create command line app with maven
Create Spring Boot development environment on Vagrant
[Rails6] Create a new app with Rails [Beginner]
Create a simple on-demand batch with Spring Batch
Create Spring Boot-gradle-mysql development environment with Docker
Create Java Spring Boot project in IntelliJ
Start web application development with Spring Boot
[Rails 5] Create a new app with Rails [Beginner]
Create a Spring Boot project in intellij and exit immediately after launching
[Java] Create a jar file with both compressed and uncompressed with the jar command
Steps to create a simple camel app using Apache Camel Spring Boot starters
Run a Spring Boot project in VS Code
Create a Spring Boot application using IntelliJ IDEA
Build Spring Boot project by environment with Gradle
Java tips-Create a Spring Boot project in Gradle
Create CRUD apps with Spring Boot 2 + Thymeleaf + MyBatis
Create a multi-key map with the standard library
Create your own Utility with Thymeleaf with Spring Boot
Create Spring Boot environment with Windows + VS Code
View the Gradle task in the Spring Boot project
Create Spring Cloud Config Server with security with Spring Boot 2.0
From creating a Spring Boot project to running an application with VS Code
Until you create a Spring Boot project in Intellij and push it to Github
Create a web app that is just right for learning [Spring Boot + Thymeleaf + PostgreSQL]
Error handling when the maximum file size is exceeded when uploading a file with Spring Boot
Docker command to create Rails project with a single blow in environment without Ruby
Create a Jar file with two lines of command
Access the built-in h2db of spring boot with jdbcTemplate
[JUnit 5 compatible] Write a test using JUnit 5 with Spring boot 2.2, 2.3
Create a Chat app with WebSocket (Tyrus) + libGDX + Kotlin
Implement a simple Rest API with Spring Security with Spring Boot 2.0
[JUnit 5] Write a validation test with Spring Boot! [Parameterization test]
A memorandum when creating a REST service with Spring Boot
Until you start development with Spring Boot in eclipse 1
Deploy the Spring Boot project to Tomcat on XAMPP
Until you start development with Spring Boot in eclipse 2
I wrote a test with Spring Boot + JUnit 5 now
Hello World (console app) with Apache Camel + Spring Boot 2
Download with Spring Boot
Until you build a project described in scala with Maven and execute it with the scala command.
I tried to create a java8 development environment with Chocolatey
Change the injection target for each environment with Spring Boot 2
Create a Docker image with the Oracle JDK installed (yum