Package org.apache.maven.plugins.war
Class AbstractWarMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.plugins.war.AbstractWarMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
WarExplodedMojo,WarInPlaceMojo,WarMojo
public abstract class AbstractWarMojo extends org.apache.maven.plugin.AbstractMojoContains common jobs for WAR mojos.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classAbstractWarMojo.DefaultWarPackagingContextWarPackagingContext default implementation.
-
Field Summary
Fields Modifier and Type Field Description private org.apache.maven.archiver.MavenArchiveConfigurationarchiveThe archive configuration to use.private booleanarchiveClassesWhether a JAR file will be created for the classes in the webapp.private org.codehaus.plexus.archiver.manager.ArchiverManagerarchiverManagerTo look up Archiver/UnArchiver implementations.private org.apache.maven.artifact.handler.manager.ArtifactHandlerManagerartifactHandlerManagerprivate java.io.FileclassesDirectoryThe directory containing compiled classes.private java.io.FilecontainerConfigXMLThe path to a configuration file for the servlet container.private OverlaycurrentProjectOverlayprivate java.util.LinkedHashSet<java.lang.String>delimitersSet of delimiters for expressions to filter within the resources.private java.lang.StringdependentWarExcludesThe comma separated list of tokens to exclude when doing a WAR overlay.private java.lang.StringdependentWarIncludesThe comma separated list of tokens to include when doing a WAR overlay.private booleanescapedBackslashesInFilePathTo escape interpolated values with Windows pathc:\foo\barwill be replaced withc:\\foo\\bar.protected java.lang.StringescapeStringExpression preceded with this String won't be interpolated.protected java.lang.BooleanfailOnMissingWebXmlWhether to fail the build if theweb.xmlfile is missing.private booleanfilteringDeploymentDescriptorsTo filter deployment descriptors.private java.util.List<java.lang.String>filtersFilters (property files) to include during the interpolation of the pom.xml.private booleanincludeEmptyDirectoriesprivate org.codehaus.plexus.archiver.jar.JarArchiverjarArchiverThe JAR archiver needed for archiving the classes directory into a JAR file under WEB-INF/lib.private org.apache.maven.shared.filtering.MavenFileFiltermavenFileFilterprivate org.apache.maven.shared.filtering.MavenResourcesFilteringmavenResourcesFilteringprivate static java.lang.StringMETA_INFprivate java.util.List<java.lang.String>nonFilteredFileExtensionsA list of file extensions that should not be filtered.private java.lang.StringoutdatedCheckPathPath prefix for resources that will be checked against outdated content.private java.lang.StringoutputFileNameMappingThe file name mapping to use when copying libraries and TLDs.protected java.lang.StringoutputTimestampTimestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXXor as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).private java.util.List<Overlay>overlaysThe overlays to apply.private java.lang.StringpackagingExcludesThe comma separated list of tokens to exclude from the WAR before packaging.private java.lang.StringpackagingIncludesThe comma separated list of tokens to include in the WAR before packaging.private org.apache.maven.project.MavenProjectprojectThe Maven project.protected java.lang.StringpropertiesEncodingThe character encoding to use when reading and writing filtered properties files.private booleanrecompressZippedFilesIndicates if zip archives (jar,zip etc) being added to the war should be compressed again.private java.lang.StringresourceEncodingThe encoding to use when copying filtered web resources.private org.apache.maven.execution.MavenSessionsessionprivate booleansupportMultiLineFilteringStop searching endToken at the end of line.private booleanuseDefaultDelimitersUse default delimiters in addition to custom delimiters, if any.private java.io.FilewarSourceDirectorySingle directory for extra files to include in the WAR.private java.lang.StringwarSourceExcludesThe comma separated list of tokens to exclude when copying the content of the warSourceDirectory.private java.lang.StringwarSourceIncludesThe comma separated list of tokens to include when copying the content of the warSourceDirectory.private static java.lang.StringWEB_INFprivate java.io.FilewebappDirectoryThe directory where the webapp is built.private org.apache.maven.model.Resource[]webResourcesThe list of webResources we want to transfer.private java.io.FilewebXmlThe path to the web.xml file to use.private java.io.FileworkDirectoryDirectory to unpack dependent WARs into if needed.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractWarMojo(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.execution.MavenSession session)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddOverlay(Overlay overlay)voidbuildExplodedWebapp(java.io.File webapplicationDirectory)voidbuildWebapp(org.apache.maven.project.MavenProject mavenProject, java.io.File webapplicationDirectory)Builds the webapp for the specified project with the new packaging task thingy.org.apache.maven.archiver.MavenArchiveConfigurationgetArchive()org.codehaus.plexus.archiver.manager.ArchiverManagergetArchiverManager()java.io.FilegetClassesDirectory()java.io.FilegetContainerConfigXML()OverlaygetCurrentProjectOverlay()protected java.lang.String[]getDependentWarExcludes()Returns a string array of the excludes to be used when adding dependent WAR as an overlay onto this WAR.protected java.lang.String[]getDependentWarIncludes()Returns a string array of the includes to be used when adding dependent WARs as an overlay onto this WAR.protected java.lang.String[]getExcludes()Returns a string array of the excludes to be used when copying the content of the WAR source directory.java.util.List<java.lang.String>getFilters()protected java.lang.String[]getIncludes()Returns a string array of the includes to be used when assembling/copying the WAR.org.codehaus.plexus.archiver.jar.JarArchivergetJarArchiver()java.util.List<java.lang.String>getNonFilteredFileExtensions()java.lang.StringgetOutputFileNameMapping()java.util.List<Overlay>getOverlays()java.lang.String[]getPackagingExcludes()java.lang.String[]getPackagingIncludes()private java.util.List<WarPackagingTask>getPackagingTasks(OverlayManager overlayManager)Returns aListof theWarPackagingTaskinstances to invoke to perform the packaging.org.apache.maven.project.MavenProjectgetProject()protected org.apache.maven.execution.MavenSessiongetSession()java.io.FilegetWarSourceDirectory()java.lang.StringgetWarSourceExcludes()java.lang.StringgetWarSourceIncludes()java.io.FilegetWebappDirectory()org.apache.maven.model.Resource[]getWebResources()java.io.FilegetWebXml()java.io.FilegetWorkDirectory()booleanisArchiveClasses()protected booleanisIncludeEmptyDirectories()protected booleanisRecompressZippedFiles()voidsetClassesDirectory(java.io.File classesDirectory)voidsetContainerConfigXML(java.io.File containerConfigXML)voidsetOutputFileNameMapping(java.lang.String outputFileNameMapping)voidsetOverlays(java.util.List<Overlay> overlays)voidsetPackagingExcludes(java.lang.String packagingExcludes)voidsetPackagingIncludes(java.lang.String packagingIncludes)voidsetProject(org.apache.maven.project.MavenProject project)voidsetWarSourceDirectory(java.io.File warSourceDirectory)voidsetWebappDirectory(java.io.File webappDirectory)voidsetWebResources(org.apache.maven.model.Resource[] webResources)voidsetWebXml(java.io.File webXml)-
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
-
-
-
Field Detail
-
META_INF
private static final java.lang.String META_INF
- See Also:
- Constant Field Values
-
WEB_INF
private static final java.lang.String WEB_INF
- See Also:
- Constant Field Values
-
failOnMissingWebXml
@Parameter protected java.lang.Boolean failOnMissingWebXml
Whether to fail the build if theweb.xmlfile is missing. Set tofalseif you want your WAR built without aweb.xmlfile. This may be useful if you are building an overlay that has no web.xml file.Starting with 3.1.0, this property defaults to
falseif the project depends on the Servlet 3.0 API or newer.- Since:
- 2.1-alpha-2
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject projectThe Maven project.
-
classesDirectory
@Parameter(defaultValue="${project.build.outputDirectory}", required=true, readonly=true) private java.io.File classesDirectoryThe directory containing compiled classes.
-
archiveClasses
@Parameter(defaultValue="false") private boolean archiveClasses
Whether a JAR file will be created for the classes in the webapp. Using this optional configuration parameter will make the compiled classes to be archived into a JAR file in/WEB-INF/lib/and the classes directory will then be excluded from the webapp/WEB-INF/classes/.- Since:
- 2.0.1
-
resourceEncoding
@Parameter(defaultValue="${project.build.sourceEncoding}") private java.lang.String resourceEncodingThe encoding to use when copying filtered web resources.- Since:
- 2.3
-
propertiesEncoding
@Parameter protected java.lang.String propertiesEncoding
The character encoding to use when reading and writing filtered properties files. If not specified, it will default to the value of the "resourceEncoding" parameter.- Since:
- 3.4.0
-
webappDirectory
@Parameter(defaultValue="${project.build.directory}/${project.build.finalName}", required=true) private java.io.File webappDirectoryThe directory where the webapp is built.
-
warSourceDirectory
@Parameter(defaultValue="${basedir}/src/main/webapp", required=true) private java.io.File warSourceDirectorySingle directory for extra files to include in the WAR. This is where you place your JSP files.
-
webResources
@Parameter private org.apache.maven.model.Resource[] webResources
The list of webResources we want to transfer.
-
filters
@Parameter private java.util.List<java.lang.String> filters
Filters (property files) to include during the interpolation of the pom.xml.
-
delimiters
@Parameter private java.util.LinkedHashSet<java.lang.String> delimiters
Set of delimiters for expressions to filter within the resources. These delimiters are specified in the form 'beginToken*endToken'. If no '*' is given, the delimiter is assumed to be the same for start and end.
So, the default filtering delimiters might be specified as:
<delimiters> <delimiter>${*}</delimiter> <delimiter>@</delimiter> </delimiters>Since the '@' delimiter is the same on both ends, we don't need to specify '@*@' (though we can).
- Since:
- 3.0.0
-
useDefaultDelimiters
@Parameter(defaultValue="true") private boolean useDefaultDelimiters
Use default delimiters in addition to custom delimiters, if any.- Since:
- 3.0.0
-
webXml
@Parameter private java.io.File webXml
The path to the web.xml file to use.
-
containerConfigXML
@Parameter private java.io.File containerConfigXML
The path to a configuration file for the servlet container. Note that the file name may be different for different servlet containers. Apache Tomcat uses a configuration file named context.xml. The file will be copied to the META-INF directory.
-
workDirectory
@Parameter(defaultValue="${project.build.directory}/war/work", required=true) private java.io.File workDirectoryDirectory to unpack dependent WARs into if needed.
-
outputFileNameMapping
@Parameter private java.lang.String outputFileNameMapping
The file name mapping to use when copying libraries and TLDs. If no file mapping is set (default) the files are copied with their standard names.- Since:
- 2.1-alpha-1
-
warSourceIncludes
@Parameter(defaultValue="**") private java.lang.String warSourceIncludes
The comma separated list of tokens to include when copying the content of the warSourceDirectory.
-
warSourceExcludes
@Parameter private java.lang.String warSourceExcludes
The comma separated list of tokens to exclude when copying the content of the warSourceDirectory.
-
dependentWarIncludes
@Parameter private java.lang.String dependentWarIncludes
The comma separated list of tokens to include when doing a WAR overlay. Default isOverlay.DEFAULT_INCLUDES
-
dependentWarExcludes
@Parameter private java.lang.String dependentWarExcludes
The comma separated list of tokens to exclude when doing a WAR overlay. Default isOverlay.DEFAULT_EXCLUDES
-
packagingExcludes
@Parameter(property="maven.war.packagingExcludes") 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
-
overlays
@Parameter private java.util.List<Overlay> overlays
The overlays to apply. Each <overlay> element may contain:- id (defaults to
currentBuild) - groupId (if this and artifactId are null, then the current project is treated as its own overlay)
- artifactId (see above)
- classifier
- type
- includes (a list of string patterns)
- excludes (a list of string patterns)
- filtered (defaults to false)
- skip (defaults to false)
- targetPath (defaults to root of webapp structure)
- Since:
- 2.1-alpha-1
- id (defaults to
-
nonFilteredFileExtensions
@Parameter private java.util.List<java.lang.String> nonFilteredFileExtensions
A list of file extensions that should not be filtered. Will be used when filtering webResources and overlays.- Since:
- 2.1-alpha-2
-
filteringDeploymentDescriptors
@Parameter(defaultValue="false") private boolean filteringDeploymentDescriptors
To filter deployment descriptors. Disabled by default.- Since:
- 2.1-alpha-2
-
escapedBackslashesInFilePath
@Parameter(defaultValue="false") private boolean escapedBackslashesInFilePath
To escape interpolated values with Windows pathc:\foo\barwill be replaced withc:\\foo\\bar.- Since:
- 2.1-alpha-2
-
escapeString
@Parameter protected java.lang.String escapeString
Expression preceded with this String won't be interpolated.\${foo}will be replaced with${foo}.- Since:
- 2.1-beta-1
-
recompressZippedFiles
@Parameter(defaultValue="true") private boolean recompressZippedFiles
Indicates if zip archives (jar,zip etc) being added to the war should be compressed again. Compressing again can result in smaller archive size, but gives noticeably longer execution time.- Since:
- 2.3
-
includeEmptyDirectories
@Parameter(defaultValue="false") private boolean includeEmptyDirectories
- Since:
- 2.4
-
supportMultiLineFiltering
@Parameter(defaultValue="false") private boolean supportMultiLineFiltering
Stop searching endToken at the end of line.- Since:
- 2.4
-
archive
@Parameter private org.apache.maven.archiver.MavenArchiveConfiguration archive
The archive configuration to use. See Maven Archiver Reference.
-
outputTimestamp
@Parameter(defaultValue="${project.build.outputTimestamp}") protected java.lang.String outputTimestampTimestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXXor as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).- Since:
- 3.3.0
-
outdatedCheckPath
@Parameter(defaultValue="WEB-INF/lib/") private java.lang.String outdatedCheckPath
Path prefix for resources that will be checked against outdated content. Starting with 3.3.2, if a value of "/" is specified the entire webappDirectory will be checked, i.e. the "/" signifies "root".- Since:
- 3.3.1
-
currentProjectOverlay
private final Overlay currentProjectOverlay
-
jarArchiver
private final org.codehaus.plexus.archiver.jar.JarArchiver jarArchiver
The JAR archiver needed for archiving the classes directory into a JAR file under WEB-INF/lib.
-
artifactHandlerManager
private final org.apache.maven.artifact.handler.manager.ArtifactHandlerManager artifactHandlerManager
-
archiverManager
private final org.codehaus.plexus.archiver.manager.ArchiverManager archiverManager
To look up Archiver/UnArchiver implementations.
-
mavenFileFilter
private final org.apache.maven.shared.filtering.MavenFileFilter mavenFileFilter
-
mavenResourcesFiltering
private final org.apache.maven.shared.filtering.MavenResourcesFiltering mavenResourcesFiltering
-
session
private final org.apache.maven.execution.MavenSession session
-
-
Constructor Detail
-
AbstractWarMojo
protected AbstractWarMojo(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.execution.MavenSession session)
-
-
Method Detail
-
getArchiverManager
public org.codehaus.plexus.archiver.manager.ArchiverManager getArchiverManager()
-
getCurrentProjectOverlay
public Overlay getCurrentProjectOverlay()
- Returns:
- the current overlay
-
getExcludes
protected java.lang.String[] getExcludes()
Returns a string array of the excludes to be used when copying the content of the WAR source directory.- Returns:
- an array of tokens to exclude
-
getIncludes
protected java.lang.String[] getIncludes()
Returns a string array of the includes to be used when assembling/copying the WAR.- Returns:
- an array of tokens to include
-
getDependentWarExcludes
protected java.lang.String[] getDependentWarExcludes()
Returns a string array of the excludes to be used when adding dependent WAR as an overlay onto this WAR.- Returns:
- an array of tokens to exclude
-
getDependentWarIncludes
protected java.lang.String[] getDependentWarIncludes()
Returns a string array of the includes to be used when adding dependent WARs as an overlay onto this WAR.- Returns:
- an array of tokens to include
-
buildExplodedWebapp
public void buildExplodedWebapp(java.io.File webapplicationDirectory) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Parameters:
webapplicationDirectory- the web application directory- Throws:
org.apache.maven.plugin.MojoExecutionException- in case of failureorg.apache.maven.plugin.MojoFailureException- in case of failure
-
buildWebapp
public void buildWebapp(org.apache.maven.project.MavenProject mavenProject, java.io.File webapplicationDirectory) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException, java.io.IOExceptionBuilds the webapp for the specified project with the new packaging task thingy. Classes, libraries and tld files are copied to thewebappDirectoryduring this phase.- Parameters:
mavenProject- the maven projectwebapplicationDirectory- the target directory- Throws:
java.io.IOException- if an error occurred while copying the filesorg.apache.maven.plugin.MojoExecutionException- if an error occurred while packaging the webapporg.apache.maven.plugin.MojoFailureException- if an unexpected error occurred while packaging the webapp
-
getPackagingTasks
private java.util.List<WarPackagingTask> getPackagingTasks(OverlayManager overlayManager) throws org.apache.maven.plugin.MojoExecutionException
Returns aListof theWarPackagingTaskinstances to invoke to perform the packaging.- Parameters:
overlayManager- the overlay manager- Returns:
- the list of packaging tasks
- Throws:
org.apache.maven.plugin.MojoExecutionException- if the packaging tasks could not be built
-
getProject
public org.apache.maven.project.MavenProject getProject()
- Returns:
- the Maven Project
-
setProject
public void setProject(org.apache.maven.project.MavenProject project)
- Parameters:
project- the project to be set
-
getClassesDirectory
public java.io.File getClassesDirectory()
- Returns:
- the classes directory
-
setClassesDirectory
public void setClassesDirectory(java.io.File classesDirectory)
- Parameters:
classesDirectory- the classes directory to be set
-
getWebappDirectory
public java.io.File getWebappDirectory()
- Returns:
webappDirectory
-
setWebappDirectory
public void setWebappDirectory(java.io.File webappDirectory)
- Parameters:
webappDirectory- the web application directory
-
getWarSourceDirectory
public java.io.File getWarSourceDirectory()
- Returns:
warSourceDirectory
-
setWarSourceDirectory
public void setWarSourceDirectory(java.io.File warSourceDirectory)
- Parameters:
warSourceDirectory-warSourceDirectory
-
getWebXml
public java.io.File getWebXml()
- Returns:
- the
webXml
-
setWebXml
public void setWebXml(java.io.File webXml)
- Parameters:
webXml- thewebXml
-
getContainerConfigXML
public java.io.File getContainerConfigXML()
- Returns:
containerConfigXML
-
setContainerConfigXML
public void setContainerConfigXML(java.io.File containerConfigXML)
- Parameters:
containerConfigXML-containerConfigXML
-
getOutputFileNameMapping
public java.lang.String getOutputFileNameMapping()
- Returns:
outputFileNameMapping
-
setOutputFileNameMapping
public void setOutputFileNameMapping(java.lang.String outputFileNameMapping)
- Parameters:
outputFileNameMapping-outputFileNameMapping
-
setOverlays
public void setOverlays(java.util.List<Overlay> overlays)
- Parameters:
overlays-overlays
-
isArchiveClasses
public boolean isArchiveClasses()
- Returns:
archiveClasses
-
getJarArchiver
public org.codehaus.plexus.archiver.jar.JarArchiver getJarArchiver()
- Returns:
JarArchiver
-
getWebResources
public org.apache.maven.model.Resource[] getWebResources()
- Returns:
webResources
-
setWebResources
public void setWebResources(org.apache.maven.model.Resource[] webResources)
- Parameters:
webResources-webResources
-
getFilters
public java.util.List<java.lang.String> getFilters()
- Returns:
filters
-
getWorkDirectory
public java.io.File getWorkDirectory()
- Returns:
workDirectory
-
getWarSourceIncludes
public java.lang.String getWarSourceIncludes()
- Returns:
warSourceIncludes
-
getWarSourceExcludes
public java.lang.String getWarSourceExcludes()
- Returns:
warSourceExcludes
-
getArchive
public org.apache.maven.archiver.MavenArchiveConfiguration getArchive()
- Returns:
archive
-
getNonFilteredFileExtensions
public java.util.List<java.lang.String> getNonFilteredFileExtensions()
- Returns:
nonFilteredFileExtensions
-
getSession
protected org.apache.maven.execution.MavenSession getSession()
- Returns:
session
-
isRecompressZippedFiles
protected boolean isRecompressZippedFiles()
- Returns:
recompressZippedFiles
-
isIncludeEmptyDirectories
protected boolean isIncludeEmptyDirectories()
- Returns:
includeEmptyDirectories
-
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
-
-