eclipse 使用maven 构建springboot 项目初体验

1、创建Maven项目

打开Eclipse,点击File->New->Other,在弹出对话框中,选中Maven Project。

eclipse 使用maven 构建springboot 项目初体验

2、点击Next按钮,出现下图,根据自己需要设置,也可以使用默认的。

eclipse 使用maven 构建springboot 项目初体验

3、再点击Next按钮,出现下图,选中图中红色框内的选项。

eclipse 使用maven 构建springboot 项目初体验

4、再点击Next按钮,设置Group Id和Artifact Id,其他项可以不用设置。

eclipse 使用maven 构建springboot 项目初体验

然后点击Finish按钮,完成项目的创建。

5、编写pom.xml

  1. <project xmlns="http://maven.apache.org/POM/4.0.0"
  2.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  4.     <modelVersion>4.0.0</modelVersion>
  5.     <groupId>com.spingBoot</groupId>
  6.     <artifactId>springBootTest</artifactId>
  7.     <packaging>war</packaging>
  8.     <version>0.0.1-SNAPSHOT</version>
  9.     <name>springBootTest Maven Webapp</name>
  10.     <url>http://maven.apache.org</url>
  11.     <!-- 继承父包 -->
  12.     <parent>
  13.         <groupId>org.springframework.boot</groupId>
  14.         <artifactId>spring-boot-starter-parent</artifactId>
  15.         <version>2.0.3.RELEASE</version>
  16.         <relativePath />
  17.     </parent>
  18.     <properties>
  19.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  20.         <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  21.         <java.version>1.8</java.version>
  22.     </properties>
  23.     <dependencies>
  24.         <!-- spring-boot的web启动的jar包 -->
  25.         <dependency>
  26.             <groupId>org.springframework.boot</groupId>
  27.             <artifactId>spring-boot-starter-web</artifactId>
  28.         </dependency>
  29.         
  30.         <dependency>
  31.             <groupId>junit</groupId>
  32.             <artifactId>junit</artifactId>
  33.             <version>3.8.1</version>
  34.             <scope>test</scope>
  35.         </dependency>
  36.     </dependencies>
  37.     <build>
  38.         <finalName>springBootTest</finalName>
  39.     </build>
  40. </project>

6、测试Spring Boot 应用

新建HelloWorld,SpringBootTestApplication类,如下图:

eclipse 使用maven 构建springboot 项目初体验

eclipse 使用maven 构建springboot 项目初体验

eclipse 使用maven 构建springboot 项目初体验

7、启动程序,右键AppleApplication.java文件,选择run as -> Java Application,如图:

eclipse 使用maven 构建springboot 项目初体验

8、启动运行如下图

eclipse 使用maven 构建springboot 项目初体验

9、如果没有报错的话,在浏览器中输入: http://localhost:8080/ 

eclipse 使用maven 构建springboot 项目初体验

至此,可以自己试试,体验一下,初次体验很重要,不要急......