Package com.google.cloud.tools.jib.api
Class JavaContainerBuilder
- java.lang.Object
-
- com.google.cloud.tools.jib.api.JavaContainerBuilder
-
public class JavaContainerBuilder extends java.lang.Object
Creates aJibContainerBuilder
for containerizing Java applications.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
JavaContainerBuilder.LayerType
Represents the different types of layers for a Java application.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_APP_ROOT
The default app root in the image.static java.lang.String
DEFAULT_WEB_APP_ROOT
Deprecated.Use the string"/jetty/webapps/ROOT"
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method 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.nio.file.Path... dependencyFiles)
Adds dependency JARs to the image.JavaContainerBuilder
addDependencies(java.util.List<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.lang.String... jvmFlags)
Adds JVM flags 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
addProjectDependencies(java.nio.file.Path... dependencyFiles)
Adds project dependency JARs to the image.JavaContainerBuilder
addProjectDependencies(java.util.List<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.nio.file.Path... dependencyFiles)
Adds snapshot dependency JARs to the image.JavaContainerBuilder
addSnapshotDependencies(java.util.List<java.nio.file.Path> dependencyFiles)
Adds snapshot dependency JARs to the image.JavaContainerBuilder
addToClasspath(java.nio.file.Path... otherFiles)
Adds additional files to the classpath.JavaContainerBuilder
addToClasspath(java.util.List<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 newJavaContainerBuilder
with the specified base image reference.static JavaContainerBuilder
from(RegistryImage registryImage)
Creates a newJavaContainerBuilder
with the specified base image.static JavaContainerBuilder
from(TarImage tarImage)
Starts building the container from a tarball.static JavaContainerBuilder
from(java.lang.String baseImageReference)
Creates a newJavaContainerBuilder
with the specified base image reference.static JavaContainerBuilder
fromDistroless()
Deprecated.Usefrom()
with the image referencegcr.io/distroless/java
.static JavaContainerBuilder
fromDistrolessJetty()
Deprecated.Usefrom()
with the image referencegcr.io/distroless/java/jetty
and change the app root by callingJavaContainerBuilder.setAppRoot("/jetty/webapps/ROOT")
.JavaContainerBuilder
setAppRoot(com.google.cloud.tools.jib.api.buildplan.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(com.google.cloud.tools.jib.api.buildplan.RelativeUnixPath classesDestination)
Sets the destination directory of the classes added to the container (relative to the app root).JavaContainerBuilder
setDependenciesDestination(com.google.cloud.tools.jib.api.buildplan.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(com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider modificationTimeProvider)
Sets the modification time provider for container files.JavaContainerBuilder
setOthersDestination(com.google.cloud.tools.jib.api.buildplan.RelativeUnixPath othersDestination)
Sets the destination directory of additional classpath files added to the container (relative to the app root).JavaContainerBuilder
setResourcesDestination(com.google.cloud.tools.jib.api.buildplan.RelativeUnixPath resourcesDestination)
Sets the destination directory of the resources added to the container (relative to the app root).JibContainerBuilder
toContainerBuilder()
Returns a newJibContainerBuilder
using the parameters specified on theJavaContainerBuilder
.
-
-
-
Field Detail
-
DEFAULT_APP_ROOT
public static final java.lang.String DEFAULT_APP_ROOT
The default app root in the image. For example, if this is set to"/app"
, dependency JARs will be in"/app/libs"
.- See Also:
- Constant Field Values
-
DEFAULT_WEB_APP_ROOT
@Deprecated public static final java.lang.String DEFAULT_WEB_APP_ROOT
Deprecated.Use the string"/jetty/webapps/ROOT"
.The default webapp root in the image. For example, if this is set to"/jetty/webapps/ROOT"
, dependency JARs will be in"/jetty/webapps/ROOT/WEB-INF/lib"
.- See Also:
- Constant Field Values
-
-
Method Detail
-
fromDistroless
@Deprecated public static JavaContainerBuilder fromDistroless()
Deprecated.Usefrom()
with the image referencegcr.io/distroless/java
.Creates a newJavaContainerBuilder
that uses distroless java as the base image. For more information ongcr.io/distroless/java
, see the distroless repository.- Returns:
- a new
JavaContainerBuilder
- See Also:
- The distroless repository
-
fromDistrolessJetty
@Deprecated public static JavaContainerBuilder fromDistrolessJetty()
Deprecated.Usefrom()
with the image referencegcr.io/distroless/java/jetty
and change the app root by callingJavaContainerBuilder.setAppRoot("/jetty/webapps/ROOT")
.Creates a newJavaContainerBuilder
that uses distroless jetty as the base image. For more information ongcr.io/distroless/java
, see the distroless repository.- Returns:
- a new
JavaContainerBuilder
- See Also:
- The distroless repository
-
from
public static JavaContainerBuilder from(java.lang.String baseImageReference) throws InvalidImageReferenceException
Creates a newJavaContainerBuilder
with the specified base image reference. The type of base image can be specified using a prefix; seeJib.from(String)
for the accepted prefixes.- Parameters:
baseImageReference
- the base image reference- Returns:
- a new
JavaContainerBuilder
- Throws:
InvalidImageReferenceException
- ifbaseImageReference
is invalid
-
from
public static JavaContainerBuilder from(ImageReference baseImageReference)
Creates a newJavaContainerBuilder
with the specified base image reference.- Parameters:
baseImageReference
- the base image reference- Returns:
- a new
JavaContainerBuilder
-
from
public static JavaContainerBuilder from(RegistryImage registryImage)
Creates a newJavaContainerBuilder
with the specified base image.- Parameters:
registryImage
- theRegistryImage
that defines base container registry and credentials- Returns:
- a new
JavaContainerBuilder
-
from
public static JavaContainerBuilder from(DockerDaemonImage dockerDaemonImage)
Starts building the container from a base image stored in the Docker cache. Requires a running Docker daemon.- Parameters:
dockerDaemonImage
- theDockerDaemonImage
that defines the base image and Docker client- Returns:
- a new
JavaContainerBuilder
-
from
public static JavaContainerBuilder from(TarImage tarImage)
Starts building the container from a tarball.- Parameters:
tarImage
- theTarImage
that defines the path to the base image- Returns:
- a new
JavaContainerBuilder
-
setAppRoot
public JavaContainerBuilder setAppRoot(java.lang.String appRoot)
Sets the app root of the container image (useful for building WAR containers).- Parameters:
appRoot
- the absolute path of the app on the container (/app
by default)- Returns:
- this
-
setAppRoot
public JavaContainerBuilder setAppRoot(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath appRoot)
Sets the app root of the container image (useful for building WAR containers).- Parameters:
appRoot
- the absolute path of the app on the container (/app
by default)- Returns:
- this
-
setClassesDestination
public JavaContainerBuilder setClassesDestination(com.google.cloud.tools.jib.api.buildplan.RelativeUnixPath classesDestination)
Sets the destination directory of the classes added to the container (relative to the app root).- Parameters:
classesDestination
- the path to the classes directory, relative to the app root- Returns:
- this
-
setResourcesDestination
public JavaContainerBuilder setResourcesDestination(com.google.cloud.tools.jib.api.buildplan.RelativeUnixPath resourcesDestination)
Sets the destination directory of the resources added to the container (relative to the app root).- Parameters:
resourcesDestination
- the path to the resources directory, relative to the app root- Returns:
- this
-
setDependenciesDestination
public JavaContainerBuilder setDependenciesDestination(com.google.cloud.tools.jib.api.buildplan.RelativeUnixPath dependenciesDestination)
Sets the destination directory of the dependencies added to the container (relative to the app root).- Parameters:
dependenciesDestination
- the path to the dependencies directory, relative to the app root- Returns:
- this
-
setOthersDestination
public JavaContainerBuilder setOthersDestination(com.google.cloud.tools.jib.api.buildplan.RelativeUnixPath othersDestination)
Sets the destination directory of additional classpath files added to the container (relative to the app root).- Parameters:
othersDestination
- the additional classpath directory, relative to the app root- Returns:
- this
-
addDependencies
public JavaContainerBuilder addDependencies(java.util.List<java.nio.file.Path> dependencyFiles) throws java.io.IOException
Adds dependency JARs to the image. Duplicate JAR filenames across all dependencies are renamed with the filesize in order to avoid collisions.- Parameters:
dependencyFiles
- the list of dependency JARs to add to the image- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addDependencies
public JavaContainerBuilder addDependencies(java.nio.file.Path... dependencyFiles) throws java.io.IOException
Adds dependency JARs to the image. Duplicate JAR filenames across all dependencies are renamed with the filesize in order to avoid collisions.- Parameters:
dependencyFiles
- the list of dependency JARs to add to the image- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addSnapshotDependencies
public JavaContainerBuilder addSnapshotDependencies(java.util.List<java.nio.file.Path> dependencyFiles) throws java.io.IOException
Adds snapshot dependency JARs to the image. Duplicate JAR filenames across all dependencies are renamed with the filesize in order to avoid collisions.- Parameters:
dependencyFiles
- the list of dependency JARs to add to the image- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addSnapshotDependencies
public JavaContainerBuilder addSnapshotDependencies(java.nio.file.Path... dependencyFiles) throws java.io.IOException
Adds snapshot dependency JARs to the image. Duplicate JAR filenames across all dependencies are renamed with the filesize in order to avoid collisions.- Parameters:
dependencyFiles
- the list of dependency JARs to add to the image- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addProjectDependencies
public JavaContainerBuilder addProjectDependencies(java.util.List<java.nio.file.Path> dependencyFiles) throws java.io.IOException
Adds project dependency JARs to the image. Generally, project dependency are jars produced from source in this project as part of other modules/sub-projects. Duplicate JAR filenames across all dependencies are renamed with the filesize in order to avoid collisions.- Parameters:
dependencyFiles
- the list of dependency JARs to add to the image- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addProjectDependencies
public JavaContainerBuilder addProjectDependencies(java.nio.file.Path... dependencyFiles) throws java.io.IOException
Adds project dependency JARs to the image. Generally, project dependency are jars produced from source in this project as part of other modules/sub-projects. Duplicate JAR filenames across all dependencies are renamed with the filesize in order to avoid collisions.- Parameters:
dependencyFiles
- the list of dependency JARs to add to the image- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addResources
public JavaContainerBuilder addResources(java.nio.file.Path resourceFilesDirectory) throws java.io.IOException
Adds the contents of a resources directory to the image.- Parameters:
resourceFilesDirectory
- the directory containing the project's resources- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addResources
public JavaContainerBuilder addResources(java.nio.file.Path resourceFilesDirectory, java.util.function.Predicate<java.nio.file.Path> pathFilter) throws java.io.IOException
Adds the contents of a resources directory to the image.- Parameters:
resourceFilesDirectory
- the directory containing the project's resourcespathFilter
- filter that determines which files (not directories) should be added- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addClasses
public JavaContainerBuilder addClasses(java.nio.file.Path classFilesDirectory) throws java.io.IOException
Adds the contents of a classes directory to the image.- Parameters:
classFilesDirectory
- the directory containing the class files- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addClasses
public JavaContainerBuilder addClasses(java.nio.file.Path classFilesDirectory, java.util.function.Predicate<java.nio.file.Path> pathFilter) throws java.io.IOException
Adds the contents of a classes directory to the image.- Parameters:
classFilesDirectory
- the directory containing the class filespathFilter
- filter that determines which files (not directories) should be added- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addToClasspath
public JavaContainerBuilder addToClasspath(java.util.List<java.nio.file.Path> otherFiles) throws java.io.IOException
Adds additional files to the classpath. IfotherFiles
contains a directory, the files within are added recursively, maintaining the directory structure. For files inotherFiles
, files with duplicate filenames will be overwritten (e.g. ifotherFiles
contains '/loser/messages.txt' and '/winner/messages.txt', only the second 'messages.txt' is added.- Parameters:
otherFiles
- the list of files to add- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addToClasspath
public JavaContainerBuilder addToClasspath(java.nio.file.Path... otherFiles) throws java.io.IOException
Adds additional files to the classpath. IfotherFiles
contains a directory, the files within are added recursively, maintaining the directory structure. For files inotherFiles
, files with duplicate filenames will be overwritten (e.g. ifotherFiles
contains '/loser/messages.txt' and '/winner/messages.txt', only the second 'messages.txt' is added.- Parameters:
otherFiles
- the list of files to add- Returns:
- this
- Throws:
java.io.IOException
- if adding the layer fails
-
addJvmFlag
public JavaContainerBuilder addJvmFlag(java.lang.String jvmFlag)
Adds a JVM flag to use when starting the application.- Parameters:
jvmFlag
- the JVM flag to add- Returns:
- this
-
addJvmFlags
public JavaContainerBuilder addJvmFlags(java.util.List<java.lang.String> jvmFlags)
Adds JVM flags to use when starting the application.- Parameters:
jvmFlags
- the list of JVM flags to add- Returns:
- this
-
addJvmFlags
public JavaContainerBuilder addJvmFlags(java.lang.String... jvmFlags)
Adds JVM flags to use when starting the application.- Parameters:
jvmFlags
- the list of JVM flags to add- Returns:
- this
-
setMainClass
public JavaContainerBuilder setMainClass(java.lang.String mainClass)
Sets the container entrypoint with the specified main class. The entrypoint will be left unconfigured if this method is not called. To find the main class from.class
files, useMainClassFinder
.- Parameters:
mainClass
- the main class used to start the application- Returns:
- this
- See Also:
MainClassFinder
-
setModificationTimeProvider
public JavaContainerBuilder setModificationTimeProvider(com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider modificationTimeProvider)
Sets the modification time provider for container files.- Parameters:
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 path- Returns:
- this
-
toContainerBuilder
public JibContainerBuilder toContainerBuilder() throws java.io.IOException
Returns a newJibContainerBuilder
using the parameters specified on theJavaContainerBuilder
.- Returns:
- a new
JibContainerBuilder
using the parameters specified on theJavaContainerBuilder
- Throws:
java.io.IOException
- if building theJibContainerBuilder
fails.
-
-