Class ModularJarArchiver

  • All Implemented Interfaces:
    Archiver, FinalizerEnabled
    Direct Known Subclasses:
    JarToolModularJarArchiver

    public abstract class ModularJarArchiver
    extends JarArchiver
    Base class for creating modular JAR archives. Subclasses are required to be able to handle both JAR archives with module descriptor (modular JAR) and without ("regular" JAR). That would allow clients of this class to use it without prior knowledge if the classes they are going to add are part of module (contain module descriptor class) or not.

    The class allows you to set the module main class (setModuleMainClass(String)), but if it is not set or it is set to null, then the Main-Class attribute of the JAR manifest is used (if present) to set the module main class.

    Since:
    3.6
    • Constructor Detail

      • ModularJarArchiver

        public ModularJarArchiver()
    • Method Detail

      • getModuleMainClass

        public String getModuleMainClass()
      • setModuleMainClass

        public void setModuleMainClass​(String moduleMainClass)
        Sets the module main class. Ignored if the JAR file does not contain module descriptor.

        Note that implementations may choose to replace the value set in the manifest as well.

        Parameters:
        moduleMainClass - the module main class.
      • getModuleVersion

        public String getModuleVersion()
      • setModuleVersion

        public void setModuleVersion​(String moduleVersion)
        Sets the module version. Ignored if the JAR file does not contain module descriptor.
        Parameters:
        moduleVersion - the module version.
      • getManifestMainClass

        protected String getManifestMainClass()
        Returns the "Main-Class" attribute of the manifest added to the archive. null if there is no manifest or the attribute is not set.
        Returns:
        the "Main-Class" attribute of the manifest
      • createManifest

        protected Manifest createManifest()
        Description copied from class: JarArchiver
        Creates the manifest to be added to the JAR archive. Sub-classes may choose to override this method in order to inspect or modify the JAR manifest file.
        Overrides:
        createManifest in class JarArchiver
        Returns:
        the manifest for the JAR archive.