- First we will create a basic java project and then we will modify it into spring boot
Syntax :
mvn archetype:generate -DgroupId={project-packaging} -DartifactId={project-name} -DarchetypeArtifactId={maven-template} -DinteractiveMode=false
Example :
mvn archetype:generate \ -DgroupId=com.heapwizard \ -DartifactId=java-maven-demo \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DinteractiveMode=false
Note: You need to execute it as a single line in terminal or by adding \
mvn archetype:generate -DgroupId=com.heapwizard -DartifactId=java-maven-demo -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
- Navigate to the directory where you have to create a the project folder. (Project folder is created by maven itself)
- Run the below maven command
Syntax :
Example :
Note: You need to execute it as a single line in terminal
- Now import the project in eclipse.
- File – Import – Existing Maven Project – Finish
Execute the default main class and test :
- Add Parent POM.xml of Spring boot for default pom.xml configuration in spring boot
<!-- Default Spring Boot configuration from Parent pom.xml --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.4.0</version> </parent>
- Add Spring boot web dependency in pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.6.1</version><!--$NO-MVN-MAN-VER$ --> </dependency>
- Note: resource folder might not be available by default in main folder, so create in manually and add it in Java Build path source folder (Add Folder Button)
- Modify Create App.java file to start spring boot
package com.heapwizard; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.task.TaskSchedulerCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication public class App { private static final Logger LOGGER = LoggerFactory.getLogger(App.class); public static void main(String[] args) { LOGGER.info("Starting spring boot application"); SpringApplication.run(App.class, args); } }
- Create an application.properties inside resource folder
server.port=9090