Experimental steps:

1. Create a SpringBoot project.

Using IntelliJ create or by spring initializrstart. Spring. IO/generation.

2. Package the project:

./gradlew build
Copy the code

3. In another empty project

Open Project Settings — > Modules and import the JAR package.

4. Return to the main screen and check the/meta-INF/manifest.mf file. Notice the last line of code.

Manifest-Version: 1.0
Start-Class: com.example.demo.DemoApplication
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Spring-Boot-Version: 2.116..RELEASE
Main-Class: org.springframework.boot.loader.JarLauncher
Copy the code

5. Open the JarLauncher file in these projects.

public static void main(String[] args) throws Exception {(new JarLauncher()).launch(args);
}
Copy the code
JarLauncher extends ExecutableArchiveLauncher
Copy the code

The main function calls the launch function of the parent class.

Keep going up until you find the MainMethodRunner class. The run function is the key.

public void run(a) throws Exception { Class<? > mainClass = Thread.currentThread().getContextClassLoader().loadClass(this.mainClassName);
        Method mainMethod = mainClass.getDeclaredMethod("main", String[].class);
        mainMethod.invoke((Object)null.this.args);
}
Copy the code

This function gets the main function via reflection and executes it.