public class JavaContainerBuilder
extends java.lang.Object
JibContainerBuilder
for containerizing Java applications.Modifier and Type | Class and Description |
---|---|
static class |
JavaContainerBuilder.LayerType
Represents the different types of layers for a Java application.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_APP_ROOT
The default app root in the image.
|
static java.lang.String |
DEFAULT_WEB_APP_ROOT
The default webapp root in the image.
|
Modifier and Type | Method and Description |
---|---|
JavaContainerBuilder |
addClasses(java.nio.file.Path classFilesDirectory)
Adds the contents of a classes directory to the image.
|
JavaContainerBuilder |
addClasses(java.nio.file.Path classFilesDirectory,
java.util.function.Predicate<java.nio.file.Path> pathFilter)
Adds the contents of a classes directory to the image.
|
JavaContainerBuilder |
addDependencies(java.util.List<java.nio.file.Path> dependencyFiles)
Adds dependency JARs to the image.
|
JavaContainerBuilder |
addDependencies(java.nio.file.Path... dependencyFiles)
Adds dependency JARs to the image.
|
JavaContainerBuilder |
addJvmFlag(java.lang.String jvmFlag)
Adds a JVM flag to use when starting the application.
|
JavaContainerBuilder |
addJvmFlags(java.util.List<java.lang.String> jvmFlags)
Adds JVM flags to use when starting the application.
|
JavaContainerBuilder |
addJvmFlags(java.lang.String... jvmFlags)
Adds JVM flags to use when starting the application.
|
JavaContainerBuilder |
addProjectDependencies(java.util.List<java.nio.file.Path> dependencyFiles)
Adds project dependency JARs to the image.
|
JavaContainerBuilder |
addProjectDependencies(java.nio.file.Path... dependencyFiles)
Adds project dependency JARs to the image.
|
JavaContainerBuilder |
addResources(java.nio.file.Path resourceFilesDirectory)
Adds the contents of a resources directory to the image.
|
JavaContainerBuilder |
addResources(java.nio.file.Path resourceFilesDirectory,
java.util.function.Predicate<java.nio.file.Path> pathFilter)
Adds the contents of a resources directory to the image.
|
JavaContainerBuilder |
addSnapshotDependencies(java.util.List<java.nio.file.Path> dependencyFiles)
Adds snapshot dependency JARs to the image.
|
JavaContainerBuilder |
addSnapshotDependencies(java.nio.file.Path... dependencyFiles)
Adds snapshot dependency JARs to the image.
|
JavaContainerBuilder |
addToClasspath(java.util.List<java.nio.file.Path> otherFiles)
Adds additional files to the classpath.
|
JavaContainerBuilder |
addToClasspath(java.nio.file.Path... otherFiles)
Adds additional files to the classpath.
|
static JavaContainerBuilder |
from(DockerDaemonImage dockerDaemonImage)
Starts building the container from a base image stored in the Docker cache.
|
static JavaContainerBuilder |
from(ImageReference baseImageReference)
Creates a new
JavaContainerBuilder with the specified base image reference. |
static JavaContainerBuilder |
from(RegistryImage registryImage)
Creates a new
JavaContainerBuilder with the specified base image. |
static JavaContainerBuilder |
from(java.lang.String baseImageReference)
Creates a new
JavaContainerBuilder with the specified base image reference. |
static JavaContainerBuilder |
from(TarImage tarImage)
Starts building the container from a tarball.
|
static JavaContainerBuilder |
fromDistroless()
Creates a new
JavaContainerBuilder that uses distroless java as the base image. |
static JavaContainerBuilder |
fromDistrolessJetty()
Creates a new
JavaContainerBuilder that uses distroless jetty as the base image. |
JavaContainerBuilder |
setAppRoot(AbsoluteUnixPath appRoot)
Sets the app root of the container image (useful for building WAR containers).
|
JavaContainerBuilder |
setAppRoot(java.lang.String appRoot)
Sets the app root of the container image (useful for building WAR containers).
|
JavaContainerBuilder |
setClassesDestination(RelativeUnixPath classesDestination)
Sets the destination directory of the classes added to the container (relative to the app
root).
|
JavaContainerBuilder |
setDependenciesDestination(RelativeUnixPath dependenciesDestination)
Sets the destination directory of the dependencies added to the container (relative to the app
root).
|
JavaContainerBuilder |
setMainClass(java.lang.String mainClass)
Sets the container entrypoint with the specified main class.
|
JavaContainerBuilder |
setModificationTimeProvider(java.util.function.BiFunction<java.nio.file.Path,AbsoluteUnixPath,java.time.Instant> modificationTimeProvider)
Sets the modification time provider for container files.
|
JavaContainerBuilder |
setOthersDestination(RelativeUnixPath othersDestination)
Sets the destination directory of additional classpath files added to the container (relative
to the app root).
|
JavaContainerBuilder |
setResourcesDestination(RelativeUnixPath resourcesDestination)
Sets the destination directory of the resources added to the container (relative to the app
root).
|
JibContainerBuilder |
toContainerBuilder()
Returns a new
JibContainerBuilder using the parameters specified on the JavaContainerBuilder . |
public static final java.lang.String DEFAULT_APP_ROOT
"/app"
, dependency
JARs will be in "/app/libs"
.public static final java.lang.String DEFAULT_WEB_APP_ROOT
"/jetty/webapps/ROOT"
, dependency JARs will be in "/jetty/webapps/ROOT/WEB-INF/lib"
.public static JavaContainerBuilder fromDistroless()
JavaContainerBuilder
that uses distroless java as the base image. For
more information on gcr.io/distroless/java
, see the distroless repository.JavaContainerBuilder
public static JavaContainerBuilder fromDistrolessJetty()
JavaContainerBuilder
that uses distroless jetty as the base image. For
more information on gcr.io/distroless/java
, see the distroless repository.JavaContainerBuilder
public static JavaContainerBuilder from(java.lang.String baseImageReference) throws InvalidImageReferenceException
JavaContainerBuilder
with the specified base image reference. The type of
base image can be specified using a prefix; see Jib.from(String)
for the accepted
prefixes.baseImageReference
- the base image referenceJavaContainerBuilder
InvalidImageReferenceException
- if baseImageReference
is invalidpublic static JavaContainerBuilder from(ImageReference baseImageReference)
JavaContainerBuilder
with the specified base image reference.baseImageReference
- the base image referenceJavaContainerBuilder
public static JavaContainerBuilder from(RegistryImage registryImage)
JavaContainerBuilder
with the specified base image.registryImage
- the RegistryImage
that defines base container registry and
credentialsJavaContainerBuilder
public static JavaContainerBuilder from(DockerDaemonImage dockerDaemonImage)
dockerDaemonImage
- the DockerDaemonImage
that defines the base image and Docker
clientJavaContainerBuilder
public static JavaContainerBuilder from(TarImage tarImage)
tarImage
- the TarImage
that defines the path to the base imageJavaContainerBuilder
public JavaContainerBuilder setAppRoot(java.lang.String appRoot)
appRoot
- the absolute path of the app on the container (/app
by default)public JavaContainerBuilder setAppRoot(AbsoluteUnixPath appRoot)
appRoot
- the absolute path of the app on the container (/app
by default)public JavaContainerBuilder setClassesDestination(RelativeUnixPath classesDestination)
classesDestination
- the path to the classes directory, relative to the app rootpublic JavaContainerBuilder setResourcesDestination(RelativeUnixPath resourcesDestination)
resourcesDestination
- the path to the resources directory, relative to the app rootpublic JavaContainerBuilder setDependenciesDestination(RelativeUnixPath dependenciesDestination)
dependenciesDestination
- the path to the dependencies directory, relative to the app rootpublic JavaContainerBuilder setOthersDestination(RelativeUnixPath othersDestination)
othersDestination
- the additional classpath directory, relative to the app rootpublic JavaContainerBuilder addDependencies(java.util.List<java.nio.file.Path> dependencyFiles) throws java.io.IOException
dependencyFiles
- the list of dependency JARs to add to the imagejava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addDependencies(java.nio.file.Path... dependencyFiles) throws java.io.IOException
dependencyFiles
- the list of dependency JARs to add to the imagejava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addSnapshotDependencies(java.util.List<java.nio.file.Path> dependencyFiles) throws java.io.IOException
dependencyFiles
- the list of dependency JARs to add to the imagejava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addSnapshotDependencies(java.nio.file.Path... dependencyFiles) throws java.io.IOException
dependencyFiles
- the list of dependency JARs to add to the imagejava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addProjectDependencies(java.util.List<java.nio.file.Path> dependencyFiles) throws java.io.IOException
dependencyFiles
- the list of dependency JARs to add to the imagejava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addProjectDependencies(java.nio.file.Path... dependencyFiles) throws java.io.IOException
dependencyFiles
- the list of dependency JARs to add to the imagejava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addResources(java.nio.file.Path resourceFilesDirectory) throws java.io.IOException
resourceFilesDirectory
- the directory containing the project's resourcesjava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addResources(java.nio.file.Path resourceFilesDirectory, java.util.function.Predicate<java.nio.file.Path> pathFilter) throws java.io.IOException
resourceFilesDirectory
- the directory containing the project's resourcespathFilter
- filter that determines which files (not directories) should be addedjava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addClasses(java.nio.file.Path classFilesDirectory) throws java.io.IOException
classFilesDirectory
- the directory containing the class filesjava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addClasses(java.nio.file.Path classFilesDirectory, java.util.function.Predicate<java.nio.file.Path> pathFilter) throws java.io.IOException
classFilesDirectory
- the directory containing the class filespathFilter
- filter that determines which files (not directories) should be addedjava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addToClasspath(java.util.List<java.nio.file.Path> otherFiles) throws java.io.IOException
otherFiles
contains a directory, the files
within are added recursively, maintaining the directory structure. For files in otherFiles
, files with duplicate filenames will be overwritten (e.g. if otherFiles
contains '/loser/messages.txt' and '/winner/messages.txt', only the second 'messages.txt' is
added.otherFiles
- the list of files to addjava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addToClasspath(java.nio.file.Path... otherFiles) throws java.io.IOException
otherFiles
contains a directory, the files
within are added recursively, maintaining the directory structure. For files in otherFiles
, files with duplicate filenames will be overwritten (e.g. if otherFiles
contains '/loser/messages.txt' and '/winner/messages.txt', only the second 'messages.txt' is
added.otherFiles
- the list of files to addjava.io.IOException
- if adding the layer failspublic JavaContainerBuilder addJvmFlag(java.lang.String jvmFlag)
jvmFlag
- the JVM flag to addpublic JavaContainerBuilder addJvmFlags(java.util.List<java.lang.String> jvmFlags)
jvmFlags
- the list of JVM flags to addpublic JavaContainerBuilder addJvmFlags(java.lang.String... jvmFlags)
jvmFlags
- the list of JVM flags to addpublic JavaContainerBuilder setMainClass(java.lang.String mainClass)
.class
files,
use MainClassFinder
.mainClass
- the main class used to start the applicationMainClassFinder
public JavaContainerBuilder setModificationTimeProvider(java.util.function.BiFunction<java.nio.file.Path,AbsoluteUnixPath,java.time.Instant> modificationTimeProvider)
modificationTimeProvider
- a provider that takes a source path and destination path on the
container and returns the file modification time that should be set for that pathpublic JibContainerBuilder toContainerBuilder() throws java.io.IOException
JibContainerBuilder
using the parameters specified on the JavaContainerBuilder
.JibContainerBuilder
using the parameters specified on the JavaContainerBuilder
java.io.IOException
- if building the JibContainerBuilder
fails.