diff --git a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java index 678a2ef..e484fc8 100644 --- a/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java +++ b/src/main/java/ch/geowerkstatt/lk2dxf/mapping/ObjectMapper.java @@ -308,17 +308,21 @@ private static TransferDescription getTransferDescription() throws Ili2cExceptio // prepare path to models from resources var resourceUri = ObjectMapper.class.getResource(MODELS_RESOURCE).toURI(); + tempDir = Files.createTempDirectory("lk2dxf_"); + iliModelsPath = tempDir.toString().replace("\\", "/"); if (resourceUri.getScheme().equals("jar")) { - tempDir = Files.createTempDirectory("lk2dxf_"); try (var fs = FileSystems.newFileSystem(resourceUri, Collections.emptyMap()); var sourceFiles = Files.walk(fs.getPath(MODELS_RESOURCE)).filter(Files::isRegularFile)) { for (var source : sourceFiles.toArray(Path[]::new)) { Files.copy(source, Paths.get(tempDir.toString(), source.getFileName().toString())); } } - iliModelsPath = tempDir.toString().replace("\\", "/"); } else { - iliModelsPath = resourceUri.getPath().replaceFirst("^/", ""); + try (var sourceFiles = Files.walk(Paths.get(resourceUri))) { + for (var source : sourceFiles.toArray(Path[]::new)) { + Files.copy(source, Paths.get(tempDir.toString(), source.getFileName().toString())); + } + } } try { @@ -327,10 +331,8 @@ private static TransferDescription getTransferDescription() throws Ili2cExceptio var ili2cConfig = modelManager.getConfig(requiredModels, 0.0); return Ili2c.runCompiler(ili2cConfig); } finally { - if (tempDir != null) { - try (var stream = Files.walk(tempDir)) { - stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); - } + try (var stream = Files.walk(tempDir)) { + stream.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete); } } }