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

public abstract class AbstractTomcatMojo extends AbstractMojo
Abstract base class for all Tomcat plugin Mojos. Provides common configuration parameters and utility methods.
Since:
1.0.0
Author:
rajendarreddyj
  • Field Details

    • tomcatVersion

      @Parameter(property="tomcat.version", defaultValue="10.1.52") protected String 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

      @Parameter(property="tomcat.catalina.home") protected File catalinaHome
      Path to an existing Tomcat installation (CATALINA_HOME). If not specified or doesn't exist, Tomcat will be downloaded based on tomcatVersion.
    • catalinaBase

      @Parameter(property="tomcat.catalina.base") protected File 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 tomcatCacheDir
      Directory for caching downloaded Tomcat distributions.
    • httpPort

      @Parameter(property="tomcat.http.port", defaultValue="8080") protected int httpPort
      HTTP port for Tomcat to listen on.
    • httpHost

      @Parameter(property="tomcat.http.host", defaultValue="localhost") protected String httpHost
      HTTP host/address for Tomcat to bind to.
    • startupTimeout

      @Parameter(property="tomcat.timeout.startup", defaultValue="120000") protected long startupTimeout
      Timeout in milliseconds for Tomcat startup. Default: 120000ms (2 minutes).
    • shutdownTimeout

      @Parameter(property="tomcat.timeout.shutdown", defaultValue="30000") protected long shutdownTimeout
      Timeout in milliseconds for Tomcat shutdown. Default: 30000ms (30 seconds).
    • skip

      @Parameter(property="tomcat.skip", defaultValue="false") protected boolean skip
      Skip plugin execution entirely. Useful for CI pipelines where Tomcat should not be started.
    • javaHome

      @Parameter(property="tomcat.java.home", defaultValue="${java.home}") protected File javaHome
      Path to JDK installation (JAVA_HOME). Defaults to the JDK running Maven.
    • vmOptions

      @Parameter(property="tomcat.vm.options") protected List<String> vmOptions
      JVM options to pass to Tomcat (CATALINA_OPTS).
    • environmentVariables

      @Parameter protected Map<String,String> environmentVariables
      Environment variables to set for Tomcat process.
    • debugPort

      @Parameter(property="tomcat.debug.port", defaultValue="5005") protected int debugPort
      Port 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 debugSuspend
      Whether to suspend JVM startup until a debugger attaches. Set to true when you need to debug application initialization. Default: false (start immediately)
    • debugHost

      @Parameter(property="tomcat.debug.host", defaultValue="*") protected String 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 contextPath
      Context path for the deployed application. Use "/" for ROOT context.
    • warSourceDirectory

      @Parameter(property="tomcat.war.directory", defaultValue="${project.build.directory}/${project.build.finalName}") protected File warSourceDirectory
      Directory containing the exploded WAR to deploy.
    • deploymentOutputName

      @Parameter(property="tomcat.deployment.name") protected String 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 autopublishEnabled
      Enable automatic republishing when source files change.
    • autopublishInactivityLimit

      @Parameter(property="tomcat.autopublish.inactivity", defaultValue="30") protected int autopublishInactivityLimit
      Seconds of inactivity before auto-publish triggers.
    • classpathAdditions

      @Parameter protected List<String> 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

      protected Path resolveCatalinaHome() throws MojoExecutionException
      Resolves the CATALINA_HOME path, downloading Tomcat if necessary.
      Returns:
      the resolved CATALINA_HOME path
      Throws:
      MojoExecutionException - if resolution fails
    • downloadTomcat

      protected Path downloadTomcat() throws MojoExecutionException
      Downloads and extracts Tomcat distribution.
      Returns:
      the path to the extracted Tomcat installation
      Throws:
      MojoExecutionException - if download fails
    • validateTomcatInstallation

      protected void validateTomcatInstallation(Path tomcatPath) throws MojoExecutionException
      Validates that the path contains a valid Tomcat installation.
      Parameters:
      tomcatPath - the path to validate
      Throws:
      MojoExecutionException - if validation fails
    • validateJavaVersion

      protected void validateJavaVersion() throws MojoExecutionException
      Validates Java version compatibility with Tomcat version.
      Throws:
      MojoExecutionException - if Java version is incompatible
    • validatePortAvailable

      protected void validatePortAvailable() throws MojoExecutionException
      Validates that the HTTP port is available before starting Tomcat.
      Throws:
      MojoExecutionException - if the port is already in use
    • detectInstalledVersion

      protected String detectInstalledVersion(Path tomcatPath)
      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

      protected ServerConfiguration buildServerConfiguration() throws MojoExecutionException
      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

      protected String 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

      protected void validateDebugPortAvailable() throws MojoExecutionException
      Validates that the debug port is available.
      Throws:
      MojoExecutionException - if the debug port is already in use