Skip to content

Commit 74c5fd2

Browse files
committed
Fixed installer, went back to just checking the manifest...
1 parent 639bcbd commit 74c5fd2

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/main/java/org/mangorage/installer/Installer.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import joptsimple.OptionSet;
77
import joptsimple.OptionSpec;
88
import joptsimple.util.PathConverter;
9+
import org.mangorage.installer.core.LogUtil;
910
import org.mangorage.installer.core.UpdateChecker;
1011
import org.mangorage.installer.core.data.*;
1112
import java.io.*;
@@ -17,6 +18,7 @@
1718
import java.util.*;
1819
import java.util.concurrent.*;
1920
import java.util.jar.JarFile;
21+
import java.util.jar.Manifest;
2022
import java.util.stream.Collectors;
2123
import java.util.zip.ZipEntry;
2224
import java.util.zip.ZipInputStream;
@@ -204,17 +206,17 @@ private static void deleteUnusedDependencies(List<File> existingJars, Set<String
204206
}
205207

206208
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;
214216
}
215217
}
216218
} 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);
218220
}
219221
return "";
220222
}

0 commit comments

Comments
 (0)