Class Packager

java.lang.Object
org.springframework.boot.loader.tools.Packager
Direct Known Subclasses:
ImagePackager, Repackager

public abstract class Packager extends Object
Abstract base class for packagers.
Since:
2.3.0
Author:
Phillip Webb, Andy Wilkinson, Stephane Nicoll, Madhura Bhave, Scott Frederick
  • Constructor Details

    • Packager

      protected Packager(File source)
      Create a new Packager instance.
      Parameters:
      source - the source archive file to package
  • Method Details

    • addMainClassTimeoutWarningListener

      public void addMainClassTimeoutWarningListener(Packager.MainClassTimeoutWarningListener listener)
      Add a listener that will be triggered to display a warning if searching for the main class takes too long.
      Parameters:
      listener - the listener to add
    • setMainClass

      public void setMainClass(String mainClass)
      Sets the main class that should be run. If not specified the value from the MANIFEST will be used, or if no manifest entry is found the archive will be searched for a suitable class.
      Parameters:
      mainClass - the main class name
    • setLayout

      public void setLayout(Layout layout)
      Sets the layout to use for the jar. Defaults to Layouts.forFile(File).
      Parameters:
      layout - the layout
    • setLoaderImplementation

      public void setLoaderImplementation(LoaderImplementation loaderImplementation)
      Sets the loader implementation to use.
      Parameters:
      loaderImplementation - the loaderImplementation to set
    • setLayoutFactory

      public void setLayoutFactory(LayoutFactory layoutFactory)
      Sets the layout factory for the jar. The factory can be used when no specific layout is specified.
      Parameters:
      layoutFactory - the layout factory to set
    • setLayers

      public void setLayers(Layers layers)
      Sets the layers that should be used in the jar.
      Parameters:
      layers - the jar layers
    • setBackupFile

      protected void setBackupFile(File backupFile)
      Sets the File to use to back up the original source.
      Parameters:
      backupFile - the file to use to back up the original source
    • setIncludeRelevantJarModeJars

      public void setIncludeRelevantJarModeJars(boolean includeRelevantJarModeJars)
      Sets if jarmode jars relevant for the packaging should be automatically included.
      Parameters:
      includeRelevantJarModeJars - if relevant jars are included
    • isAlreadyPackaged

      protected final boolean isAlreadyPackaged()
    • isAlreadyPackaged

      protected final boolean isAlreadyPackaged(File file)
    • write

      protected final void write(JarFile sourceJar, Libraries libraries, AbstractJarWriter writer) throws IOException
      Throws:
      IOException
    • write

      protected final void write(JarFile sourceJar, Libraries libraries, AbstractJarWriter writer, boolean ensureReproducibleBuild) throws IOException
      Throws:
      IOException
    • writeSignatureFileIfNecessary

      protected void writeSignatureFileIfNecessary(Map<String,Library> writtenLibraries, AbstractJarWriter writer) throws IOException
      Writes a signature file if necessary for the given writtenLibraries.
      Parameters:
      writtenLibraries - the libraries
      writer - the writer to use to write the signature file if necessary
      Throws:
      IOException - if a failure occurs when writing the signature file
    • findMainMethod

      protected String findMainMethod(JarFile source) throws IOException
      Throws:
      IOException
    • getBackupFile

      public final File getBackupFile()
      Return the File to use to back up the original source.
      Returns:
      the file to use to back up the original source
    • getSource

      protected final File getSource()
    • getLayout

      protected final Layout getLayout()