Class AbstractJarMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.apache.maven.plugins.jar.AbstractJarMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
JarMojo, TestJarMojo

public abstract class AbstractJarMojo extends org.apache.maven.plugin.AbstractMojo
Base class for creating a jar from project classes.
Version:
$Id$
  • Field Details

    • DEFAULT_EXCLUDES

      private static final String[] DEFAULT_EXCLUDES
    • DEFAULT_INCLUDES

      private static final String[] DEFAULT_INCLUDES
    • MODULE_DESCRIPTOR_FILE_NAME

      private static final String MODULE_DESCRIPTOR_FILE_NAME
      See Also:
    • includes

      @Parameter private String[] includes
      List of files to include. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.
    • excludes

      @Parameter private String[] excludes
      List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.
    • outputDirectory

      @Parameter(defaultValue="${project.build.directory}", required=true) private File outputDirectory
      Directory containing the generated JAR.
    • finalName

      @Parameter(defaultValue="${project.build.finalName}", readonly=true) private String finalName
      Name of the generated JAR.
    • archivers

      @Component private Map<String,org.codehaus.plexus.archiver.Archiver> archivers
      The Jar archiver.
    • project

      @Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
      The {@link {MavenProject}.
    • session

      @Parameter(defaultValue="${session}", readonly=true, required=true) private org.apache.maven.execution.MavenSession session
      The MavenSession.
    • archive

      @Parameter private org.apache.maven.archiver.MavenArchiveConfiguration archive
      The archive configuration to use. See Maven Archiver Reference.
    • useDefaultManifestFile

      @Parameter(property="jar.useDefaultManifestFile", defaultValue="false") private boolean useDefaultManifestFile
      Deprecated.
      For version 3.0.0 this parameter is only defined here to break the build if you use it!
      Using this property will fail your build cause it has been removed from the plugin configuration. See the Major Version Upgrade to version 3.0.0 for the plugin.
    • projectHelper

      @Component private org.apache.maven.project.MavenProjectHelper projectHelper
    • forceCreation

      @Parameter(property="maven.jar.forceCreation", defaultValue="false") private boolean forceCreation
      Require the jar plugin to build a new JAR even if none of the contents appear to have changed. By default, this plugin looks to see if the output jar exists and inputs have not changed. If these conditions are true, the plugin skips creation of the jar. This does not work when other plugins, like the maven-shade-plugin, are configured to post-process the jar. This plugin can not detect the post-processing, and so leaves the post-processed jar in place. This can lead to failures when those plugins do not expect to find their own output as an input. Set this parameter to true to avoid these problems by forcing this plugin to recreate the jar every time.
      Starting with 3.0.0 the property has been renamed from jar.forceCreation to maven.jar.forceCreation.
    • skipIfEmpty

      @Parameter(defaultValue="false") private boolean skipIfEmpty
      Skip creating empty archives.
    • outputTimestamp

      @Parameter(defaultValue="${project.build.outputTimestamp}") private String outputTimestamp
      Timestamp for reproducible output archive entries, either formatted as ISO 8601 extended offset date-time (e.g. in UTC such as '2011-12-03T10:15:30Z' or with an offset '2019-10-05T20:37:42+06:00'), or as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).
      Since:
      3.2.0
  • Constructor Details

    • AbstractJarMojo

      public AbstractJarMojo()
  • Method Details

    • getClassesDirectory

      protected abstract File getClassesDirectory()
      Return the specific output directory to serve as the root for the archive.
      Returns:
      get classes directory.
    • getProject

      protected final org.apache.maven.project.MavenProject getProject()
      Returns:
      the project
    • getClassifier

      protected abstract String getClassifier()
      Overload this to produce a jar with another classifier, for example a test-jar.
      Returns:
      get the classifier.
    • getType

      protected abstract String getType()
      Overload this to produce a test-jar, for example.
      Returns:
      return the type.
    • getJarFile

      protected File getJarFile(File basedir, String resultFinalName, String classifier)
      Returns the Jar file to generate, based on an optional classifier.
      Parameters:
      basedir - the output directory
      resultFinalName - the name of the ear file
      classifier - an optional classifier
      Returns:
      the file to generate
    • createArchive

      public File createArchive() throws org.apache.maven.plugin.MojoExecutionException
      Generates the JAR.
      Returns:
      The instance of File for the created archive file.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - in case of an error.
    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException
      Generates the JAR.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - in case of an error.
    • projectHasAlreadySetAnArtifact

      private boolean projectHasAlreadySetAnArtifact()
    • hasClassifier

      protected boolean hasClassifier()
      Returns:
      true in case where the classifier is not null and contains something else than white spaces.
    • getIncludes

      private String[] getIncludes()
    • getExcludes

      private String[] getExcludes()