Uploaded image for project: 'Apache Tomcat Maven Plugin'
  1. Apache Tomcat Maven Plugin
  2. MTOMCAT-270

Additional web apps are not re-deployed properly

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2
    • Fix Version/s: None
    • Component/s: tomcat6, tomcat7
    • Labels:
      None

      Description

      Additional Web apps are exploded into a directory under the webapps folder in the Tomcat config directory - but only if this folder does not yet exist.

      org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java line 1443
              File webapps = new File( configurationDir, "webapps" );
              File artifactWarDir = new File( webapps, artifact.getArtifactId() );
              if ( !artifactWarDir.exists() )
              {
                  //dont extract if exists
                  artifactWarDir.mkdir();
                  ...
      

      If the artifact is changed (i.e. when deploying a snapshot), it is not redeployed since the directory does already exist.

      Since the directory is just named after the artifact id and does not contain group id or version, it is also not re deployed even if the version of the dependency is changed.

      Proposed fix (simple):
      If the directory exists, it should be removed before exploding the web app.
      Problem:
      This does work correctly, but will cause some overhead since it will be always re-deploying.

      Proposed optimal fix:
      1. The deployment directory where the webapp is exploded to should consist of groupId, artifactId and version, and not just the artifact id.
      For example:

      org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java suggested change
           private void addContextFromArtifact( Tomcat container, List<Context> contexts, Artifact artifact,
                                               String contextPath, File contextXml, boolean asWebApp )
              throws MojoExecutionException, ServletException, IOException
          {
              getLog().info( "Deploy warfile: " + String.valueOf( artifact.getFile() ) + " to contextPath: " + contextPath );
              File webapps = new File( configurationDir, "webapps" );
              File artifactWarDir = new File( webapps, artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() );
              if ( !artifactWarDir.exists() )
              ...
      

      2. The timestamp of the directory should be compared against the timestamp of the war file. If the war file is newer, the directory is deleted and redeployed:

      org/apache/tomcat/maven/plugin/tomcat7/run/AbstractRunMojo.java suggested change
              getLog().info( "Deploy warfile: " + String.valueOf( artifact.getFile() ) + " to contextPath: " + contextPath );
              File webapps = new File( configurationDir, "webapps" );
              File artifactWarDir = new File( webapps, artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" + artifact.getVersion() );
              if( artifactWarDir.exists() )
              {
                  if( artifact.getFile().lastModified() > artifactWarDir.lastModified() )
                  {
                      FileUtils.deleteDirectory( artifactWarDir );
                  }
              }
              if ( !artifactWarDir.exists() )
              {
                  //dont extract if exists
                  artifactWarDir.mkdir();
                  try
                  {
      

      Please note that the changed directory layout proposed by this fix influences the fix proposed in MTOMCAT-269

        Attachments

          Activity

            People

            • Assignee:
              olamy Olivier Lamy
              Reporter:
              skopf.alfresco Stefan Kopf
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: