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,20 +47,23 @@ 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) { while (entries.hasMoreElements()) {
throw new RuntimeException(e); JarEntry entry = entries.nextElement();
} if (entry.isDirectory()) {
while (entries.hasMoreElements()) { continue;
JarEntry entry = entries.nextElement(); }
if (entry.isDirectory()) { fileNames.add(entry.getName());
continue;
} }
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<>(