Class Repackager
- java.lang.Object
- org.springframework.boot.loader.tools.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'.
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
Repackager.MainClassTimeoutWarningListener
Callback interface used to present a warning when finding the main class takes too long.
Constructor Summary
Constructors Constructor Description Repackager(File source)
Repackager(File source, LayoutFactory layoutFactory)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.protected String
findMainMethod(JarFile source)
File
getBackupFile()
Return theFile
to use to backup the original source.void
repackage(File destination, Libraries libraries)
Repackage to the given destination so that it can be launched using ' java -jar'.void
repackage(File destination, Libraries libraries, LaunchScript launchScript)
Repackage to the given destination so that it can be launched using ' java -jar'.void
repackage(Libraries libraries)
Repackage the source file so that it can be run using 'java -jar'.void
setBackupSource(boolean backupSource)
Sets if source files should be backed up when they would be overwritten.void
setLayout(Layout layout)
Sets the layout to use for the jar.void
setLayoutFactory(LayoutFactory layoutFactory)
Sets the layout factory for the jar.void
setMainClass(String mainClass)
Sets the main class that should be run.
Constructor Detail
Repackager
public Repackager(File source)
Repackager
public Repackager(File source, LayoutFactory layoutFactory)
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 toLayouts.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 archivelaunchScript
- 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 theFile
to use to backup the original source.- Returns:
- the file to use to backup the original source
findMainMethod
protected String findMainMethod(JarFile source) throws IOException
- Throws:
IOException