Skip to content

Commit 59b8fc6

Browse files
author
Dave Syer
committed
Scan for a valid MANIFEST.MF instead of taking the first one
Fixes spring-projectsgh-1321
1 parent bacbff1 commit 59b8fc6

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

spring-boot-cli/src/main/java/org/springframework/boot/cli/jar/PackagedSpringApplicationLauncher.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.lang.reflect.Method;
2020
import java.net.URL;
2121
import java.net.URLClassLoader;
22+
import java.util.Enumeration;
2223
import java.util.jar.Manifest;
2324

2425
/**
@@ -31,6 +32,8 @@ public class PackagedSpringApplicationLauncher {
3132

3233
public static final String SOURCE_MANIFEST_ENTRY = "Spring-Application-Source-Classes";
3334

35+
public static final String MAIN_CLASS_MANIFEST_ENTRY = "Start-Class";
36+
3437
private static final String SPRING_APPLICATION_CLASS = "org.springframework.boot.SpringApplication";
3538

3639
private void run(String[] args) throws Exception {
@@ -42,10 +45,19 @@ private void run(String[] args) throws Exception {
4245
}
4346

4447
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");
4961
}
5062

5163
private Class<?>[] loadClasses(ClassLoader classLoader, String[] names)

0 commit comments

Comments
 (0)