Search code examples
springmaven-3maven-plugintomcat8

How to auto clear Tomcat temp directory on server startup through maven


I want to delete all the files and subdirectories from the temp folder of Tomcat 8+ version.

In my application ActiveMQ is integrated which will create one folder inside temp folder of Tomcat on the server startup. So I want to clear my temp folder before creating another folder by ActiveMQ on server startup.

Is there any way to define any maven plugin to achieve this or there is any other way to get this done?


Solution

  • As I can understand you need to clean directories that are not exposed to maven.

    So check this clean plugin for maven

      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>3.1.0</version>
        <configuration>
          <filesets>
            <fileset>
              <directory>some/relative/path</directory>
              <includes>
                <include>**/*.tmp</include>
                <include>**/*.log</include>
              </includes>
              <excludes>
                <exclude>**/important.log</exclude>
                <exclude>**/another-important.log</exclude>
              </excludes>
              <followSymlinks>false</followSymlinks>
            </fileset>
          </filesets>
        </configuration>
      </plugin>