Compare commits

...

2 Commits

Author SHA1 Message Date
fszimnau
8be9cf81d7 work with jar file before closing it 2025-11-25 09:21:53 +01:00
fszimnau
7df22a2d1f improved/ added error messages 2025-11-20 09:07:29 +01:00

View File

@@ -47,14 +47,14 @@ public class Main {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
List<String> fileNames = new ArrayList<>(); List<String> fileNames = new ArrayList<>();
URL jarUrl = classLoader.getResource("de/szimnau/zeitlaeufer"); URL jarUrl = classLoader.getResource("de/szimnau/zeitlaeufer");
if (jarUrl == null) {
throw new RuntimeException("Kann ausführbare Klassen nicht eruieren, da keine Ressource \"de/szimnau/zeitlaeufer\" verfügbar.");
}
String path = jarUrl.getPath().split(":", 2)[1]; String path = jarUrl.getPath().split(":", 2)[1];
String cleanPath = path.substring(0, path.lastIndexOf('!')); String cleanPath = path.substring(0, path.lastIndexOf('!'));
Enumeration<JarEntry> entries; Enumeration<JarEntry> entries;
try (var jarFile = new JarFile(URLDecoder.decode(cleanPath, StandardCharsets.UTF_8))) { try (var jarFile = new JarFile(URLDecoder.decode(cleanPath, StandardCharsets.UTF_8))) {
entries = jarFile.entries(); entries = jarFile.entries();
} catch (IOException e) {
throw new RuntimeException(e);
}
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement(); JarEntry entry = entries.nextElement();
if (entry.isDirectory()) { if (entry.isDirectory()) {
@@ -62,6 +62,9 @@ public class Main {
} }
fileNames.add(entry.getName()); fileNames.add(entry.getName());
} }
} catch (IOException e) {
throw new RuntimeException("Kann JAR-Datei zwecks Reflection nicht öffnen:", e);
}
var increment = new AtomicInteger(); var increment = new AtomicInteger();
return Collections.unmodifiableSortedMap(new TreeMap<>( return Collections.unmodifiableSortedMap(new TreeMap<>(
fileNames.stream() fileNames.stream()