public class JavaContainerBuilder extends 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 String |
DEFAULT_APP_ROOT
The default app root in the image.
|
static String |
DEFAULT_WEB_APP_ROOT
The default webapp root in the image.
|
| Modifier and Type | Method and Description |
|---|---|
JavaContainerBuilder |
addClasses(Path classFilesDirectory)
Adds the contents of a classes directory to the image.
|
JavaContainerBuilder |
addClasses(Path classFilesDirectory,
Predicate<Path> pathFilter)
Adds the contents of a classes directory to the image.
|
JavaContainerBuilder |
addDependencies(List<Path> dependencyFiles)
Adds dependency JARs to the image.
|
JavaContainerBuilder |
addDependencies(Path... dependencyFiles)
Adds dependency JARs to the image.
|
JavaContainerBuilder |
addJvmFlag(String jvmFlag)
Adds a JVM flag to use when starting the application.
|
JavaContainerBuilder |
addJvmFlags(List<String> jvmFlags)
Adds JVM flags to use when starting the application.
|
JavaContainerBuilder |
addJvmFlags(String... jvmFlags)
Adds JVM flags to use when starting the application.
|
JavaContainerBuilder |
addResources(Path resourceFilesDirectory)
Adds the contents of a resources directory to the image.
|
JavaContainerBuilder |
addResources(Path resourceFilesDirectory,
Predicate<Path> pathFilter)
Adds the contents of a resources directory to the image.
|
JavaContainerBuilder |
addToClasspath(List<Path> otherFiles)
Adds additional files to the classpath.
|
JavaContainerBuilder |
addToClasspath(Path... otherFiles)
Adds additional files to the classpath.
|
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(String baseImageReference)
Creates a new
JavaContainerBuilder with the specified base image reference. |
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(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(String mainClass)
Sets the container entrypoint with the specified main class.
|
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 String DEFAULT_APP_ROOT
"/app", dependency
JARs will be in "/app/libs".public static final 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.JavaContainerBuilderpublic static JavaContainerBuilder fromDistrolessJetty()
JavaContainerBuilder that uses distroless jetty as the base image. For
more information on gcr.io/distroless/java, see the distroless repository.JavaContainerBuilderpublic static JavaContainerBuilder from(String baseImageReference) throws InvalidImageReferenceException
JavaContainerBuilder with the specified base image reference.baseImageReference - the base image referenceJavaContainerBuilderInvalidImageReferenceException - if baseImageReference is invalidpublic static JavaContainerBuilder from(ImageReference baseImageReference)
JavaContainerBuilder with the specified base image reference.baseImageReference - the base image referenceJavaContainerBuilderpublic static JavaContainerBuilder from(RegistryImage registryImage)
JavaContainerBuilder with the specified base image.registryImage - the RegistryImage that defines base container registry and
credentialsJavaContainerBuilderpublic JavaContainerBuilder setAppRoot(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(List<Path> dependencyFiles) throws IOException
dependencyFiles - the list of dependency JARs to add to the imageIOException - if adding the layer failspublic JavaContainerBuilder addDependencies(Path... dependencyFiles) throws IOException
dependencyFiles - the list of dependency JARs to add to the imageIOException - if adding the layer failspublic JavaContainerBuilder addResources(Path resourceFilesDirectory) throws IOException
resourceFilesDirectory - the directory containing the project's resourcesIOException - if adding the layer failspublic JavaContainerBuilder addResources(Path resourceFilesDirectory, Predicate<Path> pathFilter) throws IOException
resourceFilesDirectory - the directory containing the project's resourcespathFilter - filter that determines which files (not directories) should be addedIOException - if adding the layer failspublic JavaContainerBuilder addClasses(Path classFilesDirectory) throws IOException
classFilesDirectory - the directory containing the class filesIOException - if adding the layer failspublic JavaContainerBuilder addClasses(Path classFilesDirectory, Predicate<Path> pathFilter) throws IOException
classFilesDirectory - the directory containing the class filespathFilter - filter that determines which files (not directories) should be addedIOException - if adding the layer failspublic JavaContainerBuilder addToClasspath(List<Path> otherFiles) throws 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 addIOException - if adding the layer failspublic JavaContainerBuilder addToClasspath(Path... otherFiles) throws 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 addIOException - if adding the layer failspublic JavaContainerBuilder addJvmFlag(String jvmFlag)
jvmFlag - the JVM flag to addpublic JavaContainerBuilder addJvmFlags(List<String> jvmFlags)
jvmFlags - the list of JVM flags to addpublic JavaContainerBuilder addJvmFlags(String... jvmFlags)
jvmFlags - the list of JVM flags to addpublic JavaContainerBuilder setMainClass(String mainClass)
.class files,
use MainClassFinder.mainClass - the main class used to start the applicationMainClassFinderpublic JibContainerBuilder toContainerBuilder() throws IOException
JibContainerBuilder using the parameters specified on the JavaContainerBuilder.JibContainerBuilder using the parameters specified on the JavaContainerBuilderIOException - if building the JibContainerBuilder fails.Copyright © 2019. All rights reserved.