jdb org.springframework.boot.loader.JarLauncher
stop in org.springframework.boot.loader.JarLauncher.main
run
我们先看看
new JarLauncher() 的启动过程。
-----------------------------------------
在这个对象构造过程中,比较重要的一个函数是
this.archive = createArchive();
那么这个函数到底执行了什么呢?
我把debug过程中的每个值都打印出来了,如下
protected final Archive createArchive() throws Exception {
//
//
//main[1] print protectionDomain
// protectionDomain = "ProtectionDomain (file:/root/springboot_tomcat_jetty_zipkin_brave_debug/ <no signer certificates>)
// sun.misc.Launcher$AppClassLoader@18b4aac2
// <no principals>
//java.security.Permissions@73a8dfcc (
// ("java.io.FilePermission" "/root/springboot_tomcat_jetty_zipkin_brave_debug/-" "read")
// ("java.lang.RuntimePermission" "exitVM")
//)
ProtectionDomain protectionDomain = getClass().getProtectionDomain();
//
//main[1] print codeSource
//codeSource = "(file:/root/springboot_tomcat_jetty_zipkin_brave_debug/ <no signer certificates>)"
CodeSource codeSource = protectionDomain.getCodeSource();
//
//main[1] print location
// location = "file:/root/springboot_tomcat_jetty_zipkin_brave_debug/"
URI location = (codeSource == null ? null : codeSource.getLocation().toURI());
//
//main[1] print path
//path = "/root/springboot_tomcat_jetty_zipkin_brave_debug/"
String path = (location == null ? null : location.getSchemeSpecificPart());
if (path == null) {
throw new IllegalStateException("Unable to determine code source archive");
}
//
//main[1] print root
//root = "/root/springboot_tomcat_jetty_zipkin_brave_debug"
File root = new File(path);
if (!root.exists()) {
throw new IllegalStateException(
"Unable to determine code source archive from " + root);
}
//
return (root.isDirectory() ? new ExplodedArchive(root)
: new JarFileArchive(root));
}
---接下来,我们看到最后一行是有2个分支,
其实就是说这个类是哪个哪个地方来的,目录就走分支1,jar包就走分支2,
平时是从jar包,我这里是从debug文件夹来的,所有就走分支1,下面开始debug分支1.
反正原理都是大差不离的。
===接下来,在构造ExplodedArchive对象的过程中,最重要的细节是读取MANIFEST文件,
见源码:
/**
* Create a new {@link ExplodedArchive} instance.
* @param root the root folder
* @param recursive if recursive searching should be used to locate the manifest.
* Defaults to {@code true}, folders with a large tree might want to set this to {code
* false}.
*/
public ExplodedArchive(File root, boolean recursive) {
//
if (!root.exists() || !root.isDirectory()) {
throw new IllegalArgumentException("Invalid source folder " + root);
}
//
this.root = root;
this.recursive = recursive;
//
this.manifestFile = getManifestFile(root);
}
private File getManifestFile(File root) {
File metaInf = new File(root, "META-INF");
return new File(metaInf, "MANIFEST.MF");
}
这个就不用解释了吧,已经拿到了MANIFEST.MF文件。
直接复制这个文件的内容,如下所示:
Manifest-Version: 1.0
Built-By: travis
Start-Class: zipkin.server.ZipkinServer
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Version: 1.4.3.RELEASE
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_111
Main-Class: org.springframework.boot.loader.JarLauncher
然后就正式进入了new JarLauncher().launch(args);的.launch(args)部分,放在下一节讲解。