You can easily clean and copy static files using clean and resource plugins, but it will not work for JSP files always. If the java source in the JSP files being copied introduces a new dependency, you are not going to copy it to the lib folder. In this case, the application will break into a ClassNotFoundException .
Even if it is copied, it can still break, because the server must be configured to scan the dependency folder and update the class path. And this is the beginning of a hot deployment, which I consider ( more ).
Try also the Vinay offer. Judging by his answer, it seems that the tc server supports dependency scanning by default, and with the correct maven build this might be a satisfactory solution.
To clear and copy static files from the source folder to where it is deployed:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-clean-plugin</artifactId> <version>2.5</version> <executions> <execution> <id>clean-loaded</id> <phase>compile</phase> <goals> <goal>clean</goal> </goals> <configuration> <excludeDefaultDirectories>true</excludeDefaultDirectories> <filesets> <fileset> <directory>${path.server.input}</directory> <followSymlinks>false</followSymlinks> <useDefaultExcludes>false</useDefaultExcludes> <includes> <include>**/*.jsp</include> <include>**/*.js</include> <include>**/*.html</include> <include>**/*.css</include> <include>**/*.png</include> <include>**/*.gif</include> <include>**/*.jpg</include> <include>**/*.jpeg</include> </includes> </fileset> </filesets> </configuration> </execution> </executions> </plugin> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>2.6</version> <executions> <execution> <id>copy-compile-output</id> <phase>compile</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${path.server.input}</outputDirectory> <overwrite>true</overwrite> <includeEmptyDirs>true</includeEmptyDirs> <filtering>true</filtering> <resources> <resource> <directory>${path.jsp.source}</directory> <targetPath>${path.element.jsp.deploy}</targetPath> <includes> <include>**/*.jsp</include> </includes> </resource> <resource> <directory>${path.static.source}</directory> <targetPath>${path.element.static.deploy}</targetPath> <includes> <include>**/*.js</include> <include>**/*.html</include> <include>**/*.css</include> <include>**/*.png</include> <include>**/*.gif</include> <include>**/*.jpg</include> <include>**/*.jpeg</include> </includes> </resource> </resources> </configuration> </execution> </executions> </plugin>
add this to the properties section:
<path.server.input>ABSOLUTE_PATH_TO_DEPLOYED_WEBAPP_ROOT</path.server.input> <path.jsp.source>ABSOLUTE_PATH_TO_JSP_SOURCE_ROOT</path.jsp.source> <path.static.source>ABSOLUTE_PATH_TO_STATIC_SOURCE_ROOT</path.static.source> <path.element.jsp.deploy>REALTIVE_PATH_TO_JSP_DEPLOY_ROOT</path.element.jsp.deploy> <path.element.static.deploy>REALTIVE_PATH_TO_STATIC_DEPLOY_ROOT</path.element.static.deploy>
Properties starting with path must be absolute paths or starting with ${project.basedir} or similar. Properties starting with path.element are relative paths, which means that they should not be added with / or starting with another property, which is an absolute path. This is because the resource plugin copies to outputDirectory/targetPath ( resources:copy-resources , resource )
In my experience, the IDE usually associates its actions with a clean and strict UI at compile time. In addition, the IDE usually has a way to display a shell command or maven user target to be visible from the user interface menu.
To run using clean-and-build
Plugins are already tied to the compilation phase. To ensure that a clean plug-in runs before the resource plug-in at the end of the compilation step, put them together at the end of the plug-ins section. It doesnβt matter if the plugin is defined twice, just make sure that when reading pom from above, the first pure definition of the plugin occurs before the definition of the first resource plugin.
Perform as a separate action
Change under the execution tag for both:
<id>default-cli</id> <phase>never</phase>
and now it will not start in the compile phase, but by a call from the command line:
mvn clean:clean resources:copy-resources
In this case, placing the plugin definitions in pom does not matter, since you define their order with the order of the command arguments. If this suits you, your IDE most likely has a way to display this command as a custom target visible from the UI menu.
In both cases, I recommend that you back up the project folder when you start it for the first time.