diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/Archive.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/Archive.java index 9d032f473f..c4a512e107 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/Archive.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/Archive.java @@ -30,7 +30,7 @@ import org.springframework.boot.loader.Launcher; * @author Phillip Webb * @see JarFileArchive */ -public interface Archive extends Iterable { +public interface Archive extends Iterable, AutoCloseable { /** * Returns a URL that can be used to load the archive. @@ -54,6 +54,16 @@ public interface Archive extends Iterable { */ List getNestedArchives(EntryFilter filter) throws IOException; + /** + * Closes the {@code Archive}, releasing any open resources. + * @throws Exception if an error occurs during close processing + * @since 2.2.0 + */ + @Override + default void close() throws Exception { + + } + /** * Represents a single entry in the archive. */ diff --git a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/JarFileArchive.java b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/JarFileArchive.java index 31dd40b00c..34b8ab0772 100755 --- a/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/JarFileArchive.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-loader/src/main/java/org/springframework/boot/loader/archive/JarFileArchive.java @@ -94,6 +94,11 @@ public class JarFileArchive implements Archive { return new EntryIterator(this.jarFile.entries()); } + @Override + public void close() throws IOException { + this.jarFile.close(); + } + protected Archive getNestedArchive(Entry entry) throws IOException { JarEntry jarEntry = ((JarFileEntry) entry).getJarEntry(); if (jarEntry.getComment().startsWith(UNPACK_MARKER)) {