Class JavaContainerBuilder


  • public class JavaContainerBuilder
    extends java.lang.Object
    Creates a JibContainerBuilder for containerizing Java applications.
    • 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

      • 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 resources
        pathFilter - 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 files
        pathFilter - 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. If 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.
        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. If 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.
        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, use MainClassFinder.
        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