搭建非maven spring boot项目 并且idea进行打包

1.所需jar包

搭建非maven spring boot项目 并且idea进行打包

搭建非maven spring boot项目 并且idea进行打包

2.搭建web项目

搭建非maven spring boot项目 并且idea进行打包

3

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringBootTemplateApplications {

    public static void main(String[] args) {
    //SpringBoot程序启动入口
        SpringApplication.run(SpringBootTemplateApplications.class, args);
    }
}

4

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SampleController {
    //处理请求地址映射的注解
    @RequestMapping(value="/hello",method=RequestMethod.GET)
    public String hello() {
    //相应的内容
        return "hello World";
    }

}

5 启动

搭建非maven spring boot项目 并且idea进行打包

访问

搭建非maven spring boot项目 并且idea进行打包

IDEA 打包项目

一、检查项目是否包含META-INF文件夹。若包含META-INF文件夹,将其删除。等待重新生成

搭建非maven spring boot项目 并且idea进行打包

二、构建Artifacts

2.1 选择菜单中的 File->Project Structure 。 在弹出的Project Structure中选择 Artifacts-> + -> JAR ->From modules with dependencies

搭建非maven spring boot项目 并且idea进行打包

 

2.2 在弹出的窗口中选择要打包的模块和主函数,然后选择要打成散包还是一个整体。

搭建非maven spring boot项目 并且idea进行打包

Module: 模块,选择需要打包的模块。如果程序没有分模块,那么只有一个可以选择的。
MainClass:选择程序的入口类。
extract to the target JAR:抽取到目标JAR。选择该项则会将所依赖的jar包全都打到一个jar文件中。
copy to the output directory and link via manifest:将依赖的jar复制到输出目录并且使用manifest链接它们。
Direct for META-INF/MANIFEST.MF: 如果上面选择了 "copy to ... "这一项,这里需要选择生成的manifest文件在哪个目录下。
Include tests: 是否包含tests。 一般这里不选即可。

选择OK,会在刚才选择的文件夹下面生成一个META-INF文件夹,下面有一个MANIFEST.MF文件

搭建非maven spring boot项目 并且idea进行打包

MANIFEST.MF
主要一下几个:
Manifest-Version: Manifest文件的版本,这个不用管。
Class-Path: 描述lib包相对生成的jar的路径。
Main-Class: 程序的入口类

三、将生成的MANIFEST.MF增添到JAR包

搭建非maven spring boot项目 并且idea进行打包

在这些jar包中,黄色的是依赖的jar包,蓝色的是我们生成的要运行的jar包。在蓝色的jar包上右键,选择 “Create Directory”(创建文件夹),名称叫做META-INF

搭建非maven spring boot项目 并且idea进行打包

在新建的“META-INF”文件夹上右键,选择Add Copy of 下的 File,选择刚刚生成的MANIFEST.MF文件。如下图 点击确定

搭建非maven spring boot项目 并且idea进行打包

点击确定

搭建非maven spring boot项目 并且idea进行打包

四、生成Jar包。

配置完上述后。选择菜单中的 build -> build artifacts...

搭建非maven spring boot项目 并且idea进行打包

搭建非maven spring boot项目 并且idea进行打包

此时页面中间会弹出要生成的jar包,选择刚刚构建的Artifacts,选择build或者rebuild

Build:只将主Jar包重新生成,不重新生成所依赖的Jar包。
Rebuild: 将所有jar包重新生成。

此时生成jar包已经完成

搭建非maven spring boot项目 并且idea进行打包

搭建非maven spring boot项目 并且idea进行打包

Jar包启动

cmd 进入到文件夹下 java -jar xxx.jar

搭建非maven spring boot项目 并且idea进行打包