Class WarMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

    @Mojo(name="war",
          defaultPhase=PACKAGE,
          threadSafe=true,
          requiresDependencyResolution=COMPILE_PLUS_RUNTIME)
    public class WarMojo
    extends AbstractWarMojo
    Build a WAR file.
    • Field Detail

      • outputDirectory

        @Parameter(defaultValue="${project.build.directory}",
                   required=true)
        private java.lang.String outputDirectory
        The directory for the generated WAR.
      • warName

        @Parameter(defaultValue="${project.build.finalName}",
                   required=true,
                   readonly=true)
        private java.lang.String warName
        The name of the generated WAR.
      • classifier

        @Parameter
        private java.lang.String classifier
        Classifier to add to the generated WAR. If given, the artifact will be an attachment instead. The classifier will not be applied to the JAR file of the project - only to the WAR file.
      • packagingExcludes

        @Parameter
        private java.lang.String packagingExcludes
        The comma separated list of tokens to exclude from the WAR before packaging. This option may be used to implement the skinny WAR use case. Note that you can use the Java Regular Expressions engine to include and exclude specific pattern using the expression %regex[]. Hint: read the about (?!Pattern).
        Since:
        2.1-alpha-2
      • packagingIncludes

        @Parameter
        private java.lang.String packagingIncludes
        The comma separated list of tokens to include in the WAR before packaging. By default everything is included. This option may be used to implement the skinny WAR use case. Note that you can use the Java Regular Expressions engine to include and exclude specific pattern using the expression %regex[].
        Since:
        2.1-beta-1
      • warArchiver

        @Component(role=org.codehaus.plexus.archiver.Archiver.class,
                   hint="war")
        private org.codehaus.plexus.archiver.war.WarArchiver warArchiver
        The WAR archiver.
      • projectHelper

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

        @Parameter(defaultValue="true")
        private boolean primaryArtifact
        Whether this is the main artifact being built. Set to false if you don't want to install or deploy it to the local repository instead of the default one in an execution.
      • attachClasses

        @Parameter(defaultValue="false")
        private boolean attachClasses
        Whether classes (that is the content of the WEB-INF/classes directory) should be attached to the project as an additional artifact.

        By default the classifier for the additional artifact is 'classes'. You can change it with the someclassifier]]> parameter.

        If this parameter true, another project can depend on the classes by writing something like:

         
           myGroup
           myArtifact
           myVersion
           classes
         ]]>
         

        Since:
        2.1-alpha-2
      • classesClassifier

        @Parameter(defaultValue="classes")
        private java.lang.String classesClassifier
        The classifier to use for the attached classes artifact.
        Since:
        2.1-alpha-2
      • skip

        @Parameter(property="maven.war.skip",
                   defaultValue="false")
        private boolean skip
        You can skip the execution of the plugin if you need to. Its use is NOT RECOMMENDED, but quite convenient on occasion.
        Since:
        3.0.0
    • Constructor Detail

      • WarMojo

        public WarMojo()
    • Method Detail

      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException,
                            org.apache.maven.plugin.MojoFailureException
        Executes the WarMojo on the current project.
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if an error occurred while building the webapp
        org.apache.maven.plugin.MojoFailureException - if an error.
      • performPackaging

        private void performPackaging​(java.io.File warFile)
                               throws java.io.IOException,
                                      org.codehaus.plexus.archiver.jar.ManifestException,
                                      org.apache.maven.artifact.DependencyResolutionRequiredException,
                                      org.apache.maven.plugin.MojoExecutionException,
                                      org.apache.maven.plugin.MojoFailureException
        Generates the webapp according to the mode attribute.
        Parameters:
        warFile - the target WAR file
        Throws:
        java.io.IOException - if an error occurred while copying files
        org.codehaus.plexus.archiver.ArchiverException - if the archive could not be created
        org.codehaus.plexus.archiver.jar.ManifestException - if the manifest could not be created
        org.apache.maven.artifact.DependencyResolutionRequiredException - if an error occurred while resolving the dependencies
        org.apache.maven.plugin.MojoExecutionException - if the execution failed
        org.apache.maven.plugin.MojoFailureException - if a fatal exception occurred
      • isProjectUsingAtLeastServlet30

        private boolean isProjectUsingAtLeastServlet30()
                                                throws org.apache.maven.artifact.DependencyResolutionRequiredException,
                                                       java.net.MalformedURLException
        Determines if the current Maven project being built uses the Servlet 3.0 API (JSR 315) or Jakarta Servlet API. If it does then the web.xml file can be omitted.

        This is done by checking if the interface javax.servlet.annotation.WebServlet or jakarta.servlet.annotation.WebServlet is in the compile-time dependencies (which includes provided dependencies) of the Maven project.

        Returns:
        true if the project being built depends on Servlet 3.0 API or Jakarta Servlet API, false otherwise.
        Throws:
        org.apache.maven.artifact.DependencyResolutionRequiredException - if the compile elements can't be resolved.
        java.net.MalformedURLException - if the path to a dependency file can't be transformed to a URL.
      • hasWebServletAnnotationClassInClasspath

        private static boolean hasWebServletAnnotationClassInClasspath​(java.lang.ClassLoader loader)
      • hasClassInClasspath

        private static boolean hasClassInClasspath​(java.lang.ClassLoader loader,
                                                   java.lang.String clazz)
      • getTargetFile

        protected static java.io.File getTargetFile​(java.io.File basedir,
                                                    java.lang.String finalName,
                                                    java.lang.String classifier,
                                                    java.lang.String type)
        Parameters:
        basedir - The basedir
        finalName - The finalName
        classifier - The classifier.
        type - The type.
        Returns:
        File
      • getTargetWarFile

        protected java.io.File getTargetWarFile()
        Returns:
        The war File
      • getTargetClassesFile

        protected java.io.File getTargetClassesFile()
        Returns:
        The target class File
      • getClassifier

        public java.lang.String getClassifier()
        Returns:
        classifier
      • setClassifier

        public void setClassifier​(java.lang.String classifier)
        Parameters:
        classifier - classifier
      • getPackagingExcludes

        public java.lang.String[] getPackagingExcludes()
        Returns:
        The package excludes.
      • setPackagingExcludes

        public void setPackagingExcludes​(java.lang.String packagingExcludes)
        Parameters:
        packagingExcludes - packagingExcludes
      • getPackagingIncludes

        public java.lang.String[] getPackagingIncludes()
        Returns:
        The packaging includes.
      • setPackagingIncludes

        public void setPackagingIncludes​(java.lang.String packagingIncludes)
        Parameters:
        packagingIncludes - packagingIncludes
      • getOutputDirectory

        public java.lang.String getOutputDirectory()
        Returns:
        outputDirectory
      • setOutputDirectory

        public void setOutputDirectory​(java.lang.String outputDirectory)
        Parameters:
        outputDirectory - outputDirectory
      • getWarName

        public java.lang.String getWarName()
        Returns:
        warName
      • setWarName

        public void setWarName​(java.lang.String warName)
        Parameters:
        warName - warName
      • getWarArchiver

        public org.codehaus.plexus.archiver.war.WarArchiver getWarArchiver()
        Returns:
        warArchiver
      • setWarArchiver

        public void setWarArchiver​(org.codehaus.plexus.archiver.war.WarArchiver warArchiver)
        Parameters:
        warArchiver - warArchiver
      • getProjectHelper

        public org.apache.maven.project.MavenProjectHelper getProjectHelper()
        Returns:
        projectHelper
      • setProjectHelper

        public void setProjectHelper​(org.apache.maven.project.MavenProjectHelper projectHelper)
        Parameters:
        projectHelper - projectHelper
      • isPrimaryArtifact

        public boolean isPrimaryArtifact()
        Returns:
        primaryArtifact
      • setPrimaryArtifact

        public void setPrimaryArtifact​(boolean primaryArtifact)
        Parameters:
        primaryArtifact - primaryArtifact
      • isAttachClasses

        public boolean isAttachClasses()
        Returns:
        attachClasses
      • setAttachClasses

        public void setAttachClasses​(boolean attachClasses)
        Parameters:
        attachClasses - attachClasses
      • getClassesClassifier

        public java.lang.String getClassesClassifier()
        Returns:
        classesClassifier
      • setClassesClassifier

        public void setClassesClassifier​(java.lang.String classesClassifier)
        Parameters:
        classesClassifier - classesClassifier
      • isSkip

        public boolean isSkip()
        Skip the mojo run
        Returns:
        skip