Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

257
Visualizações
Spring Boot ClassPathResource en un JAR

En mi aplicación Spring Boot 1.5, uso ClassPathResource para leer un archivo estático en el archivo JAR de la aplicación:

 // ... import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; @Slf4j @Service public class MyService { private Resource resource = new ClassPathResource("a.txt"); private List<String> myStrings; public MyService() { myStrings = load(resource); } private List<String> load(Resource resource) { try(Stream<String> stream = Files.lines(Paths.get(resource.getURI()))) { myStrings = stream.filter(/* my filter */) .collect(Collectors.toList()); } catch (IOException x) { log.error("Failed to read '{}'.", resource.getFilename()); } } }

pero esto falla con:

 Caused by: java.nio.file.FileSystemNotFoundException: null at com.sun.nio.zipfs.ZipFileSystemProvider.getFileSystem(ZipFileSystemProvider.java:171) ~[zipfs.jar:1.8.0_121] at com.sun.nio.zipfs.ZipFileSystemProvider.getPath(ZipFileSystemProvider.java:157) ~[zipfs.jar:1.8.0_121] at java.nio.file.Paths.get(Paths.java:143) ~[na:1.8.0_121] at MyService.load(MyService.java:53) ~[classes!/:2.0.0-SNAPSHOT] //...

¿Cómo puedo leer un ClassPathResource incrustado en mi aplicación JAR?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Paths.get de JDK no puede resolver los recursos dentro de los archivos JAR, así que reemplace:

 Files.lines(Paths.get(resource.getURI()))

con:

 new BufferedReader(new InputStreamReader(resource.getInputStream())).lines();
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda