Class Repackager


  • public class Repackager
    extends java.lang.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
    • Constructor Summary

      Constructors 
      Constructor Description
      Repackager​(java.io.File source)  
    • Method Summary

      Modifier and Type Method Description
      protected java.lang.String findMainMethod​(java.util.jar.JarFile source)  
      void repackage​(Libraries libraries)
      Repackage the source file so that it can be run using 'java -jar'.
      void repackage​(java.io.File destination, Libraries libraries)
      Repackage to the given destination so that it can be launched using ' java -jar'.
      void repackage​(java.io.File destination, Libraries libraries, LaunchScript launchScript)
      Repackage to the given destination so that it can be launched 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 setMainClass​(java.lang.String mainClass)
      Sets the main class that should be run.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Repackager

        public Repackager​(java.io.File source)
    • Method Detail

      • setMainClass

        public void setMainClass​(java.lang.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
      • repackage

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

        public void repackage​(java.io.File destination,
                              Libraries libraries)
                       throws java.io.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:
        java.io.IOException - if the file cannot be repackaged
      • repackage

        public void repackage​(java.io.File destination,
                              Libraries libraries,
                              LaunchScript launchScript)
                       throws java.io.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:
        java.io.IOException - if the file cannot be repackaged
        Since:
        1.3.0
      • findMainMethod

        protected java.lang.String findMainMethod​(java.util.jar.JarFile source)
                                           throws java.io.IOException
        Throws:
        java.io.IOException