JarUtil { public static boolean resourceExists(Path file, String resource) throws IOException { checkNotNull(resource); checkNotNull(file); if (!Files.exists(file)) throw new FileNotFoundException(); if (!resource.startsWith("/")) resource = "/" + resource; try (FileSystem fs = FileSystems.newFileSystem(file, (ClassLoader) null)) { return Files.exists(fs.getPath(resource)); } catch (ProviderNotFoundException e) { throw new IOException("Illegal file type"); } } private  JarUtil(); static Optional<String> getManifestValue(Path file, String attribute); static Optional<String> getManifestValue(File file, String attribute); static Attributes getManifest(Path file); static Attributes getManifest(File file); static long getResourceSize(Path file, String resource); static long getResourceSize(File file, String resource); static URL getResourceUrl(Path file, String resource); static boolean resourceExists(Path file, String resource);  }
@Test @DisplayName("Check for resources in a jar file") void resourceExists_1() throws IOException { assertTrue(resourceExists(Paths.get("src/test/resources/small_program.jar"), "/META-INF/MANIFEST.MF")); assertTrue(resourceExists(Paths.get("src/test/resources/small_program.jar"), "META-INF/MANIFEST.MF")); assertFalse(resourceExists(Paths.get("src/test/resources/small_program.jar"), "META-INF/MANIFEST.MF2")); }
@Test @DisplayName("Try to check for resources in a text file") void resourceExists_2() { assertThrows(IOException.class, () -> resourceExists(Paths.get("src/test/resources/small_file.txt"), "META-INF/MANIFEST.MF")); }