Package io.github.rajendarreddyj.tomcat
Class AbstractTomcatMojo
java.lang.Object
org.apache.maven.plugin.AbstractMojo
io.github.rajendarreddyj.tomcat.AbstractTomcatMojo
- All Implemented Interfaces:
ContextEnabled,Mojo
- Direct Known Subclasses:
DebugMojo,DeployMojo,RunMojo,StartMojo,StopMojo
Abstract base class for all Tomcat plugin Mojos.
Provides common configuration parameters and utility methods.
- Since:
- 1.0.0
- Author:
- rajendarreddyj
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanEnable automatic republishing when source files change.protected intSeconds of inactivity before auto-publish triggers.protected FilePath to Tomcat instance directory (CATALINA_BASE).protected FilePath to an existing Tomcat installation (CATALINA_HOME).Additional JAR files to add to Tomcat's classpath.protected StringContext path for the deployed application.protected StringHost/interface for the debug agent to bind to.protected intPort for the JDWP debug agent to listen on.protected booleanWhether to suspend JVM startup until a debugger attaches.protected StringTarget directory for deployment within webapps.Environment variables to set for Tomcat process.protected StringHTTP host/address for Tomcat to bind to.protected intHTTP port for Tomcat to listen on.protected FilePath to JDK installation (JAVA_HOME).protected org.apache.maven.project.MavenProjectprotected longTimeout in milliseconds for Tomcat shutdown.protected booleanSkip plugin execution entirely.protected longTimeout in milliseconds for Tomcat startup.protected FileDirectory for caching downloaded Tomcat distributions.protected StringTomcat version to use.JVM options to pass to Tomcat (CATALINA_OPTS).protected FileDirectory containing the exploded WAR to deploy. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected DeployableConfigurationbuildDeployableConfiguration(ServerConfiguration serverConfig) Builds DeployableConfiguration from Mojo parameters.protected StringBuilds the JDWP agent string for debug mode.protected ServerConfigurationBuilds ServerConfiguration from Mojo parameters.protected StringdetectInstalledVersion(Path tomcatPath) Detects the installed Tomcat version from an existing installation.protected PathDownloads and extracts Tomcat distribution.protected PathResolves the CATALINA_HOME path, downloading Tomcat if necessary.protected voidValidates that the debug port is available.protected voidValidates Java version compatibility with Tomcat version.protected voidValidates that the HTTP port is available before starting Tomcat.protected voidvalidateTomcatInstallation(Path tomcatPath) Validates that the path contains a valid Tomcat installation.Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
tomcatVersion
Tomcat version to use. If catalinaHome is not specified or doesn't exist, this version will be downloaded automatically. Supported versions: 10.1.x, 11.x -
catalinaHome
Path to an existing Tomcat installation (CATALINA_HOME). If not specified or doesn't exist, Tomcat will be downloaded based on tomcatVersion. -
catalinaBase
Path to Tomcat instance directory (CATALINA_BASE). Defaults to catalinaHome if not specified. -
tomcatCacheDir
@Parameter(property="tomcat.cache.dir", defaultValue="${user.home}/.m2/tomcat-cache") protected File tomcatCacheDirDirectory for caching downloaded Tomcat distributions. -
httpPort
@Parameter(property="tomcat.http.port", defaultValue="8080") protected int httpPortHTTP port for Tomcat to listen on. -
httpHost
HTTP host/address for Tomcat to bind to. -
startupTimeout
@Parameter(property="tomcat.timeout.startup", defaultValue="120000") protected long startupTimeoutTimeout in milliseconds for Tomcat startup. Default: 120000ms (2 minutes). -
shutdownTimeout
@Parameter(property="tomcat.timeout.shutdown", defaultValue="30000") protected long shutdownTimeoutTimeout in milliseconds for Tomcat shutdown. Default: 30000ms (30 seconds). -
skip
@Parameter(property="tomcat.skip", defaultValue="false") protected boolean skipSkip plugin execution entirely. Useful for CI pipelines where Tomcat should not be started. -
javaHome
Path to JDK installation (JAVA_HOME). Defaults to the JDK running Maven. -
vmOptions
JVM options to pass to Tomcat (CATALINA_OPTS). -
environmentVariables
Environment variables to set for Tomcat process. -
debugPort
@Parameter(property="tomcat.debug.port", defaultValue="5005") protected int debugPortPort for the JDWP debug agent to listen on. The debugger will connect to this port. Default: 5005 (IntelliJ IDEA default) -
debugSuspend
@Parameter(property="tomcat.debug.suspend", defaultValue="false") protected boolean debugSuspendWhether to suspend JVM startup until a debugger attaches. Set to true when you need to debug application initialization. Default: false (start immediately) -
debugHost
Host/interface for the debug agent to bind to. Use "*" to allow connections from any host (remote debugging). Use "localhost" to restrict to local connections only. Default: * (allow remote debugging) -
contextPath
@Parameter(property="tomcat.context.path", defaultValue="/${project.artifactId}") protected String contextPathContext path for the deployed application. Use "/" for ROOT context. -
warSourceDirectory
@Parameter(property="tomcat.war.directory", defaultValue="${project.build.directory}/${project.build.finalName}") protected File warSourceDirectoryDirectory containing the exploded WAR to deploy. -
deploymentOutputName
Target directory for deployment within webapps. If not specified, derived from contextPath (e.g., "ROOT" for "/"). -
autopublishEnabled
@Parameter(property="tomcat.autopublish.enabled", defaultValue="false") protected boolean autopublishEnabledEnable automatic republishing when source files change. -
autopublishInactivityLimit
@Parameter(property="tomcat.autopublish.inactivity", defaultValue="30") protected int autopublishInactivityLimitSeconds of inactivity before auto-publish triggers. -
classpathAdditions
Additional JAR files to add to Tomcat's classpath. -
project
@Parameter(defaultValue="${project}", readonly=true, required=true) protected org.apache.maven.project.MavenProject project
-
-
Constructor Details
-
AbstractTomcatMojo
public AbstractTomcatMojo()
-
-
Method Details
-
resolveCatalinaHome
Resolves the CATALINA_HOME path, downloading Tomcat if necessary.- Returns:
- the resolved CATALINA_HOME path
- Throws:
MojoExecutionException- if resolution fails
-
downloadTomcat
Downloads and extracts Tomcat distribution.- Returns:
- the path to the extracted Tomcat installation
- Throws:
MojoExecutionException- if download fails
-
validateTomcatInstallation
Validates that the path contains a valid Tomcat installation.- Parameters:
tomcatPath- the path to validate- Throws:
MojoExecutionException- if validation fails
-
validateJavaVersion
Validates Java version compatibility with Tomcat version.- Throws:
MojoExecutionException- if Java version is incompatible
-
validatePortAvailable
Validates that the HTTP port is available before starting Tomcat.- Throws:
MojoExecutionException- if the port is already in use
-
detectInstalledVersion
Detects the installed Tomcat version from an existing installation. Reads version from lib/catalina.jar!/org/apache/catalina/util/ServerInfo.properties- Parameters:
tomcatPath- path to the Tomcat installation- Returns:
- The detected version string (e.g., "10.1.52") or null if detection fails
-
buildServerConfiguration
Builds ServerConfiguration from Mojo parameters. Generates a custom CATALINA_BASE if needed for port/host configuration.- Returns:
- the ServerConfiguration
- Throws:
MojoExecutionException- if configuration fails
-
buildDeployableConfiguration
protected DeployableConfiguration buildDeployableConfiguration(ServerConfiguration serverConfig) throws MojoExecutionException Builds DeployableConfiguration from Mojo parameters.- Parameters:
serverConfig- the server configuration- Returns:
- the DeployableConfiguration
- Throws:
MojoExecutionException- if configuration fails
-
buildJdwpAgentArg
Builds the JDWP agent string for debug mode.Constructs a JDWP agent argument in the format:
-agentlib:jdwp=transport=dt_socket,server=y,suspend={n|y},address={host}:{port}- Returns:
- the JDWP agent JVM argument string
-
validateDebugPortAvailable
Validates that the debug port is available.- Throws:
MojoExecutionException- if the debug port is already in use
-