fix(StorageServiceImpl, StaticResourceServiceImpl): improve jar path handling for Windows and normalize path resolution

This commit is contained in:
extio-de
2026-06-27 15:51:43 +02:00
parent 2a8cdca80c
commit 8036c7c15a
2 changed files with 17 additions and 6 deletions

View File

@@ -28,14 +28,20 @@ public class StaticResourceServiceImpl implements StaticResourceService {
if (location == null) {
try {
final URL url = StorageServiceImpl.class.getProtectionDomain().getCodeSource().getLocation();
LOGGER.info("Code source location: {}", url);
Path parent;
if (url.toString().startsWith("jar:nested:")) {
parent = Paths.get(url.toString().substring("jar:nested:".length(), url.toString().indexOf("/!"))).getParent();
if (Objects.requireNonNullElse(System.getProperty("os.name"), "").toLowerCase().contains("windows")) {
parent = Paths.get(url.toString().substring("jar:nested:/".length(), url.toString().indexOf("/!"))).getParent();
}
else {
parent = url.toURI().toPath().getParent();
parent = Paths.get(url.toString().substring("jar:nested:".length(), url.toString().indexOf("/!"))).getParent();
}
final Path jarPath = parent != null ? parent.toAbsolutePath().normalize() : url.toURI().toPath().toAbsolutePath().normalize();
}
else {
parent = Paths.get(url.toURI()).getParent();
}
final Path jarPath = parent != null ? parent.toAbsolutePath().normalize() : Paths.get(url.toURI()).toAbsolutePath().normalize();
final String currentSubDir = jarPath.getFileName().toString();
if ("bin".equals(currentSubDir) || "target".equals(currentSubDir)) {

View File

@@ -40,12 +40,17 @@ public class StorageServiceImpl implements StorageService {
final URL url = StorageServiceImpl.class.getProtectionDomain().getCodeSource().getLocation();
Path parent;
if (url.toString().startsWith("jar:nested:")) {
parent = Paths.get(url.toString().substring("jar:nested:".length(), url.toString().indexOf("/!"))).getParent();
if (Objects.requireNonNullElse(System.getProperty("os.name"), "").toLowerCase().contains("windows")) {
parent = Paths.get(url.toString().substring("jar:nested:/".length(), url.toString().indexOf("/!"))).getParent();
}
else {
parent = url.toURI().toPath().getParent();
parent = Paths.get(url.toString().substring("jar:nested:".length(), url.toString().indexOf("/!"))).getParent();
}
final Path jarPath = parent != null ? parent.toAbsolutePath().normalize() : url.toURI().toPath().toAbsolutePath().normalize();
}
else {
parent = Paths.get(url.toURI()).getParent();
}
final Path jarPath = parent != null ? parent.toAbsolutePath().normalize() : Paths.get(url.toURI()).toAbsolutePath().normalize();
final String currentSubDir = jarPath.getFileName().toString();
if ("bin".equals(currentSubDir) || "target".equals(currentSubDir)) {