|
6 | 6 | import joptsimple.OptionSet; |
7 | 7 | import joptsimple.OptionSpec; |
8 | 8 | import joptsimple.util.PathConverter; |
| 9 | +import org.mangorage.installer.core.LogUtil; |
9 | 10 | import org.mangorage.installer.core.UpdateChecker; |
10 | 11 | import org.mangorage.installer.core.data.*; |
11 | 12 | import java.io.*; |
|
17 | 18 | import java.util.*; |
18 | 19 | import java.util.concurrent.*; |
19 | 20 | import java.util.jar.JarFile; |
| 21 | +import java.util.jar.Manifest; |
20 | 22 | import java.util.stream.Collectors; |
21 | 23 | import java.util.zip.ZipEntry; |
22 | 24 | import java.util.zip.ZipInputStream; |
@@ -204,17 +206,17 @@ private static void deleteUnusedDependencies(List<File> existingJars, Set<String |
204 | 206 | } |
205 | 207 |
|
206 | 208 | public static String findMainClass(File file) { |
207 | | - try (ZipInputStream zis = new ZipInputStream(new FileInputStream(file)); |
208 | | - BufferedReader reader = new BufferedReader(new InputStreamReader(zis))) { |
209 | | - ZipEntry entry; |
210 | | - while ((entry = zis.getNextEntry()) != null) { |
211 | | - if (SERVICE_PATH.equals(entry.getName())) { |
212 | | - org.mangorage.installer.core.LogUtil.println("Found " + SERVICE_PATH + " in " + file.getName()); |
213 | | - return reader.lines().collect(Collectors.joining("\n")); |
| 209 | + try (JarFile jar = new JarFile(file)) { |
| 210 | + Manifest manifest = jar.getManifest(); |
| 211 | + if (manifest != null) { |
| 212 | + String mainClass = manifest.getMainAttributes().getValue("Main-Class"); |
| 213 | + if (mainClass != null) { |
| 214 | + org.mangorage.installer.core.LogUtil.println("Found Main-Class: " + mainClass); |
| 215 | + return mainClass; |
214 | 216 | } |
215 | 217 | } |
216 | 218 | } catch (IOException e) { |
217 | | - throw new RuntimeException("Error processing JAR file: " + file.getName(), e); |
| 219 | + throw new RuntimeException("Failed to read JAR manifest from " + file.getName(), e); |
218 | 220 | } |
219 | 221 | return ""; |
220 | 222 | } |
|
0 commit comments