org.springframework.boot.loader.tools

Class Repackager



  • public class Repackager
    extends Object
    Utility class that can be used to repackage an archive so that it can be executed using 'java -jar'.
    Author:
    Phillip Webb, Andy Wilkinson, Stephane Nicoll
    • Constructor Detail

      • Repackager

        public Repackager(File source)
    • Method Detail

      • addMainClassTimeoutWarningListener

        public void addMainClassTimeoutWarningListener(Repackager.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
      • setBackupSource

        public void setBackupSource(boolean backupSource)
        Sets if source files should be backed up when they would be overwritten.
        Parameters:
        backupSource - if source files should be backed up
      • setLayout

        public void setLayout(Layout layout)
        Sets the layout to use for the jar. Defaults to Layouts.forFile(File).
        Parameters:
        layout - the layout
      • 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
      • repackage

        public void repackage(Libraries libraries)
                       throws IOException
        Repackage the source file so that it can be run using 'java -jar'.
        Parameters:
        libraries - the libraries required to run the archive
        Throws:
        IOException - if the file cannot be repackaged
      • repackage

        public void repackage(File destination,
                              Libraries libraries)
                       throws IOException
        Repackage to the given destination so that it can be launched using ' java -jar'.
        Parameters:
        destination - the destination file (may be the same as the source)
        libraries - the libraries required to run the archive
        Throws:
        IOException - if the file cannot be repackaged
      • repackage

        public void repackage(File destination,
                              Libraries libraries,
                              LaunchScript launchScript)
                       throws IOException
        Repackage to the given destination so that it can be launched using ' java -jar'.
        Parameters:
        destination - the destination file (may be the same as the source)
        libraries - the libraries required to run the archive
        launchScript - an optional launch script prepended to the front of the jar
        Throws:
        IOException - if the file cannot be repackaged
        Since:
        1.3.0
      • getBackupFile

        public final File getBackupFile()
        Return the File to use to backup the original source.
        Returns:
        the file to use to backup the original source