使用idea创建springboot的maven项目(jar)

创建一个maven工程(jar)

1、新建一个项目

2、导入spring boot相关的依赖

springboot创建工程官网参考地址:

https://start.spring.io/

https://spring.io/quickstart

pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.stu</groupId>
    <artifactId>springboot-helloword</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.9.RELEASE</version>
    </parent>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

3、编写一个主程序,启动Spring Boot应用

HelloWordApplication主程序

@SpringBootApplication 来标注一个主程序类,说明这是一个Spring Boot应用

package com.stu;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class HelloWordApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloWordApplication.class, args);
    }
}

4、编写相关的Controller

5、启动HelloWordApplication类里的main方法,访问游览器http://localhost:8080/hello

6、简化部署

放到pom文件的</dependencies>下边

 <!-- 这个插件,可以将应用打包成一个可执行的jar包;-->
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

7、点击idea里的maven的package进行打包。

  1. 打包路径为:Building jar: F:\zxjy_workspace\code\springboot-helloword\target\springboot-helloword-1.0-SNAPSHOT.jar。
  2. 在项目target下生成jar包文件。

 

8、运行这个jar包

把这个jar包复制到桌面,cmd命令运行,cd进入到jar的位置,执行java -jar springboot-helloword-1.0-SNAPSHOT.jar,然后游览器访问http://localhost:8080/hello

 

posted @ 2021-09-25 22:24  程序员小明1024  阅读(301)  评论(0编辑  收藏  举报