0
# OCI Image Packaging
1
2
Specialized packager for exporting fully packaged archives to OCI (Open Container Initiative) images, designed for Docker integration and container deployment workflows.
3
4
## Capabilities
5
6
### ImagePackager
7
8
Creates packaged images from Spring Boot applications, handling the conversion of JAR/WAR archives to OCI-compatible image layers.
9
10
```java { .api }
11
/**
12
* Create a new ImagePackager instance
13
* @param source the source file to package
14
* @param backupFile the backup of the source file to package
15
*/
16
public ImagePackager(File source, File backupFile);
17
18
/**
19
* Create a packaged image using a custom exporter
20
* @param libraries the contained libraries
21
* @param exporter the exporter used to write the image
22
* @throws IOException on IO error
23
*/
24
public void packageImage(Libraries libraries, BiConsumer<ZipEntry, EntryWriter> exporter) throws IOException;
25
```
26
27
**Usage Examples:**
28
29
```java
30
import org.springframework.boot.loader.tools.ImagePackager;
31
import org.springframework.boot.loader.tools.Libraries;
32
import org.springframework.boot.loader.tools.EntryWriter;
33
import java.io.File;
34
import java.util.zip.ZipEntry;
35
import java.util.function.BiConsumer;
36
37
// Create image packager with source and backup
38
File sourceJar = new File("myapp.jar");
39
File backupJar = new File("myapp.jar.original");
40
ImagePackager imagePackager = new ImagePackager(sourceJar, backupJar);
41
42
// Export to OCI image format
43
Libraries libraries = /* ... define libraries ... */;
44
BiConsumer<ZipEntry, EntryWriter> exporter = (entry, writer) -> {
45
// Custom logic to write entries to OCI image layers
46
System.out.println("Exporting: " + entry.getName());
47
// writer.write(outputStream) to write the entry content
48
};
49
50
imagePackager.packageImage(libraries, exporter);
51
```
52
53
## Core Types
54
55
```java { .api }
56
public interface EntryWriter {
57
void write(OutputStream outputStream) throws IOException;
58
default int size() { return -1; }
59
}
60
```