打包后生成jar包文件,
META-INF中有MANIFEST.MF文件
Manifest-Version: 1.0
Implementation-Title: SpringBoot
Implementation-Version: 1.0-SNAPSHOT
Archiver-Version: Plexus Archiver
Built-By: 小A
Implementation-Vendor-Id: test
Spring-Boot-Version: 1.5.2.RELEASE
Implementation-Vendor: Pivotal Software, Inc.
# 启动的类
Main-Class: org.springframework.boot.loader.JarLauncher
# 业务启动类
Start-Class: com.Application
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.5.4
Build-Jdk: 1.8.0_131
Implementation-URL: http://www.example.com
获取MANIFEST.MF中的Start-Class类
MainMethodRunner启动main函数
public void run() throws Exception {
Class<?> mainClass = Thread.currentThread().getContextClassLoader().loadClass(this.mainClassName);
Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
mainMethod.invoke(null, new Object[] { this.args });
}
JarLauncher 打包后的jar包启动类-本质是通过反射获取到main返回然后开始执行的