Package org.apache.maven.plugins.war
Class WarMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.plugins.war.AbstractWarMojo
-
- org.apache.maven.plugins.war.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 AbstractWarMojoBuild a WAR file.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanattachClassesWhether classes (that is the content of the WEB-INF/classes directory) should be attached to the project as an additional artifact.private java.lang.StringclassesClassifierThe classifier to use for the attached classes artifact.private java.lang.StringclassifierClassifier to add to the generated WAR.private java.lang.StringoutputDirectoryThe directory for the generated WAR.private booleanprimaryArtifactWhether this is the main artifact being built.private org.apache.maven.project.MavenProjectHelperprojectHelperprivate booleanskipYou can skip the execution of the plugin if you need to.private java.lang.StringwarNameThe name of the generated WAR.-
Fields inherited from class org.apache.maven.plugins.war.AbstractWarMojo
escapeString, failOnMissingWebXml, outputTimestamp, propertiesEncoding
-
-
Constructor Summary
Constructors Constructor Description WarMojo(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.codehaus.plexus.archiver.manager.ArchiverManager archiverManager, org.apache.maven.shared.filtering.MavenFileFilter mavenFileFilter, org.apache.maven.shared.filtering.MavenResourcesFiltering mavenResourcesFiltering, org.apache.maven.project.MavenProjectHelper projectHelper, org.apache.maven.execution.MavenSession session)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidexecute()Executes the WarMojo on the current project.java.lang.StringgetClassesClassifier()java.lang.StringgetClassifier()java.lang.StringgetOutputDirectory()org.apache.maven.project.MavenProjectHelpergetProjectHelper()protected java.io.FilegetTargetClassesFile()protected static java.io.FilegetTargetFile(java.io.File basedir, java.lang.String finalName, java.lang.String classifier, java.lang.String type)protected java.io.FilegetTargetWarFile()org.codehaus.plexus.archiver.war.WarArchivergetWarArchiver()java.lang.StringgetWarName()private static booleanhasClassInClasspath(java.lang.ClassLoader loader, java.lang.String clazz)private static booleanhasWebServletAnnotationClassInClasspath(java.lang.ClassLoader loader)booleanisAttachClasses()booleanisFailOnMissingWebXml()booleanisPrimaryArtifact()private booleanisProjectUsingAtLeastServlet30()Determines if the current Maven project being built uses the Servlet 3.0 API (JSR 315) or Jakarta Servlet API.booleanisSkip()Skip the mojo run.private voidperformPackaging(java.io.File warFile)Generates the webapp according to themodeattribute.voidsetAttachClasses(boolean attachClasses)voidsetClassesClassifier(java.lang.String classesClassifier)voidsetClassifier(java.lang.String classifier)voidsetFailOnMissingWebXml(boolean failOnMissingWebXml)voidsetOutputDirectory(java.lang.String outputDirectory)voidsetPrimaryArtifact(boolean primaryArtifact)voidsetWarName(java.lang.String warName)-
Methods inherited from class org.apache.maven.plugins.war.AbstractWarMojo
addOverlay, buildExplodedWebapp, buildWebapp, getArchive, getArchiverManager, getClassesDirectory, getContainerConfigXML, getCurrentProjectOverlay, getDependentWarExcludes, getDependentWarIncludes, getExcludes, getFilters, getIncludes, getJarArchiver, getNonFilteredFileExtensions, getOutputFileNameMapping, getOverlays, getPackagingExcludes, getPackagingIncludes, getProject, getSession, getWarSourceDirectory, getWarSourceExcludes, getWarSourceIncludes, getWebappDirectory, getWebResources, getWebXml, getWorkDirectory, isArchiveClasses, isIncludeEmptyDirectories, isRecompressZippedFiles, setClassesDirectory, setContainerConfigXML, setOutputFileNameMapping, setOverlays, setPackagingExcludes, setPackagingIncludes, setProject, setWarSourceDirectory, setWebappDirectory, setWebResources, setWebXml
-
-
-
-
Field Detail
-
outputDirectory
@Parameter(defaultValue="${project.build.directory}", required=true) private java.lang.String outputDirectoryThe directory for the generated WAR.
-
warName
@Parameter(defaultValue="${project.build.finalName}", required=true, readonly=true) private java.lang.String warNameThe 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.
-
primaryArtifact
@Parameter(defaultValue="true") private boolean primaryArtifact
Whether this is the main artifact being built. Set tofalseif 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 skipYou 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
-
projectHelper
private final org.apache.maven.project.MavenProjectHelper projectHelper
-
-
Constructor Detail
-
WarMojo
@Inject public WarMojo(org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager, org.codehaus.plexus.archiver.manager.ArchiverManager archiverManager, org.apache.maven.shared.filtering.MavenFileFilter mavenFileFilter, org.apache.maven.shared.filtering.MavenResourcesFiltering mavenResourcesFiltering, org.apache.maven.project.MavenProjectHelper projectHelper, org.apache.maven.execution.MavenSession session)
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionExecutes the WarMojo on the current project.- Throws:
org.apache.maven.plugin.MojoExecutionException- if an error occurred while building the webapporg.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.MojoFailureExceptionGenerates the webapp according to themodeattribute.- Parameters:
warFile- the target WAR file- Throws:
org.codehaus.plexus.archiver.ArchiverException- if the archive could not be createdorg.apache.maven.artifact.DependencyResolutionRequiredException- if an error occurred while resolving the dependenciesjava.io.IOException- if an error occurred while copying filesorg.codehaus.plexus.archiver.jar.ManifestException- if the manifest could not be createdorg.apache.maven.plugin.MojoExecutionException- if the execution failedorg.apache.maven.plugin.MojoFailureException- if a fatal exception occurred
-
isProjectUsingAtLeastServlet30
private boolean isProjectUsingAtLeastServlet30() throws org.apache.maven.artifact.DependencyResolutionRequiredException, java.net.MalformedURLExceptionDetermines if the current Maven project being built uses the Servlet 3.0 API (JSR 315) or Jakarta Servlet API. If it does then theweb.xmlfile can be omitted.This is done by checking if the interface
javax.servlet.annotation.WebServletorjakarta.servlet.annotation.WebServletis in the compile-time dependencies (which includes provided dependencies) of the Maven project.- Returns:
trueif the project being built depends on Servlet 3.0 API or Jakarta Servlet API,falseotherwise- Throws:
org.apache.maven.artifact.DependencyResolutionRequiredException- if the compile elements can't be resolvedjava.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 basedirfinalName- the finalNameclassifier- the classifiertype- 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
-
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()
-
getProjectHelper
public org.apache.maven.project.MavenProjectHelper getProjectHelper()
- Returns:
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
-
isFailOnMissingWebXml
public boolean isFailOnMissingWebXml()
- Returns:
AbstractWarMojo.failOnMissingWebXml
-
setFailOnMissingWebXml
public void setFailOnMissingWebXml(boolean failOnMissingWebXml)
- Parameters:
failOnMissingWebXml-AbstractWarMojo.failOnMissingWebXml
-
isSkip
public boolean isSkip()
Skip the mojo run.- Returns:
skip
-
-