• 使用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_workspacecodespringboot-helloword argetspringboot-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

  • 相关阅读:
    固定长度下随文字数量增加自动适配字体大小
    vue v-for 和 v-if 、v-else一起使用造成的bug
    火狐使用Ctrl新开窗口不生效
    js如何模拟multipart/form-data类型的请求
    centos安装nodejs
    cursor图标自定义
    解决 vs code 打开文件总是只有一个tab标签页,新打开的tab标签页会替换掉旧的tab标签页
    Devexpress Tab Control 文档
    Devexpress WPF教程
    Linq把一个DataTable根据一列去除重复数据
  • 原文地址:https://www.cnblogs.com/konglxblog/p/15335830.html
Copyright © 2020-2023  润新知