Spring Boot 3.2 依赖项上的 FileSystemNotFoundException

问题描述 投票:0回答:1

我最近尝试从 spring-boot 3.1.6 更新到 3.2.0 并遇到以下问题:

java.lang.ExceptionInInitializerError: null
at ai.picovoice.porcupine.Porcupine$Builder.build(Porcupine.java:242)
...
Caused by: java.nio.file.FileSystemNotFoundException: null
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:156)
at jdk.zipfs/jdk.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:142)
at java.base/java.nio.file.Path.of(Path.java:209)
at java.base/java.nio.file.Paths.get(Paths.java:98)
at ai.picovoice.porcupine.Utils.getResourceDirectory(Utils.java:58)
at ai.picovoice.porcupine.Utils.<clinit>(Utils.java:39)
... 28 common frames omitted

我试图弄清楚依赖项在哪里尝试执行此操作,并发现了类似的内容:

  private static Path getResourceDirectory() throws RuntimeException {
    URL resourceURL = Porcupine.class.getProtectionDomain().getCodeSource().getLocation();

    Path resourcePath;
    try {
      resourcePath = Paths.get(resourceURL.toURI());
    } catch (URISyntaxException var4) {
      resourcePath = Paths.get(resourceURL.getPath());
    }

    if (resourcePath.toString().endsWith(".jar")) {
      try {
        resourcePath = extractResources(resourcePath);
      } catch (IOException var3) {
        throw new RuntimeException("Failed to extract resources from Porcupine jar.");
      }
    }

    return resourcePath.resolve("porcupine");
  }

  private static Path extractResources(Path jarPath) throws IOException {
    String extractionDirName = jarPath.getFileName().toString().replace(".jar", "");
    String systemTempDir = System.getProperty("java.io.tmpdir");
    Path resourceDirectoryPath = (new File(systemTempDir, extractionDirName)).toPath();
    if (!Files.exists(resourceDirectoryPath, new LinkOption[0])) {
      try {
        Files.createDirectory(resourceDirectoryPath);
      } catch (IOException var13) {
        logger.severe("Failed to create extraction directory at " + jarPath.toString());
        var13.printStackTrace();
        resourceDirectoryPath = (new File(systemTempDir)).toPath();
      }
    }

    JarFile jf = new JarFile(jarPath.toFile());
    Enumeration<JarEntry> entries = jf.entries();

    while(entries.hasMoreElements()) {
      JarEntry jarEntry = (JarEntry)entries.nextElement();
      String jarEntryName = jarEntry.getName();
      if (jarEntryName.startsWith("porcupine")) {
        Path dstPath;
        if (jarEntry.isDirectory()) {
          dstPath = resourceDirectoryPath.resolve(jarEntryName);
          if (!dstPath.toFile().exists()) {
            Files.createDirectory(dstPath);
          }
        } else {
          dstPath = resourceDirectoryPath.resolve(jarEntryName);
          InputStream is = jf.getInputStream(jarEntry);

          try {
            Files.copy(is, dstPath, new CopyOption[]{StandardCopyOption.REPLACE_EXISTING});
          } catch (Throwable var14) {
            if (is != null) {
              try {
                is.close();
              } catch (Throwable var12) {
                var14.addSuppressed(var12);
              }
            }

            throw var14;
          }

          if (is != null) {
            is.close();
          }
        }
      }
    }

    return resourceDirectoryPath;
  }

我已经像这样解压了依赖项(在 3.1.6 中它有效):

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>net.indexoutofmj.neptune.NeptuneBot</mainClass>
                    <requiresUnpack>
                        <dependency>
                            <groupId>ai.picovoice</groupId>
                            <artifactId>picovoice-java</artifactId>
                        </dependency>
                    </requiresUnpack>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

但现在似乎失败了......我不知道为什么

有人可以帮忙吗?

提前致谢

java spring-boot maven dependencies
1个回答
0
投票

好吧,这是 Spring Boot 3.2.0 中的一个错误,从 3.2.1 开始,它就可以正常工作了

© www.soinside.com 2019 - 2024. All rights reserved.