19
19
import java .lang .reflect .Method ;
20
20
import java .net .URL ;
21
21
import java .net .URLClassLoader ;
22
+ import java .util .Enumeration ;
22
23
import java .util .jar .Manifest ;
23
24
24
25
/**
@@ -31,6 +32,8 @@ public class PackagedSpringApplicationLauncher {
31
32
32
33
public static final String SOURCE_MANIFEST_ENTRY = "Spring-Application-Source-Classes" ;
33
34
35
+ public static final String MAIN_CLASS_MANIFEST_ENTRY = "Start-Class" ;
36
+
34
37
private static final String SPRING_APPLICATION_CLASS = "org.springframework.boot.SpringApplication" ;
35
38
36
39
private void run (String [] args ) throws Exception {
@@ -42,10 +45,19 @@ private void run(String[] args) throws Exception {
42
45
}
43
46
44
47
private Object [] getSources (URLClassLoader classLoader ) throws Exception {
45
- URL url = classLoader .findResource ("META-INF/MANIFEST.MF" );
46
- Manifest manifest = new Manifest (url .openStream ());
47
- String attribute = manifest .getMainAttributes ().getValue (SOURCE_MANIFEST_ENTRY );
48
- return loadClasses (classLoader , attribute .split ("," ));
48
+ for (Enumeration <URL > urls = classLoader .findResources ("META-INF/MANIFEST.MF" ); urls
49
+ .hasMoreElements ();) {
50
+ URL url = urls .nextElement ();
51
+ Manifest manifest = new Manifest (url .openStream ());
52
+ if (getClass ().getName ().equals (
53
+ manifest .getMainAttributes ().getValue (MAIN_CLASS_MANIFEST_ENTRY ))) {
54
+ String attribute = manifest .getMainAttributes ().getValue (
55
+ SOURCE_MANIFEST_ENTRY );
56
+ return loadClasses (classLoader , attribute .split ("," ));
57
+ }
58
+ }
59
+ throw new IllegalStateException ("Cannot locate " + SOURCE_MANIFEST_ENTRY
60
+ + " in MANIFEST.MF" );
49
61
}
50
62
51
63
private Class <?>[] loadClasses (ClassLoader classLoader , String [] names )
0 commit comments