Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only copy modified files in maven-war-plugin

I'm currently using maven 3.x with the maven-war-plugin. For developer builds I would like to be able to use the war:exploaded goal, but only copy resources that have changed. Is there a way to do this?

I've been looking through the docs and have not been able to find a way to do this in the current versions, but there used to be (in the old maven 1.x version) a property maven.war.resources.overwrite that would allow this.

Thanks.

like image 377
davija Avatar asked Apr 01 '11 18:04

davija


2 Answers

I'm not aware of a way to do this using the maven-war-plugin, but if your IDE supports it, you could have the IDE auto-deploy changes. For example, the Web Tools Platform for Eclipse supports this feature for Tomcat. However, if your build process is complex or does something weird before invoking the maven-war-plugin, this may not work for you.

A second option: if you're running Linux, set up rsync to copy recently modified files to your servlet container. A co-worker did this by having the servlet container's web app directory sync with the Eclipse project's output directory, and it worked well (just modify your code, Eclipse will build it automatically, and rsync will copy your changes).

like image 158
Dave Avatar answered Oct 14 '22 01:10

Dave


For this purpose I use maven-antrun-plugin

Example:

<project xmlns="http://maven.apache.org/POM/4.0.0" 
....
....
    <!--DJ: Settings for deploy only-->
    <!--DJ: Dir to where copy files-->
    <!--DJ: And date when build have been started, to select only modified files in the future-->
    <properties>
        <tomcat.dir.rootDir>C:\apache-tomcat-6.0.35\webapps\ROOT1</tomcat.dir.rootDir>
        <maven.build.timestamp.format>yyyy-MM-dd HH:mm:ss</maven.build.timestamp.format>
    </properties>
 .....
<!--Ohter dependensies here-->
 .....
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copyModifiedFilesFrom_ExplodedWAR_Dir</id>
                        <phase>install</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <echo message="Upload new files to dir ${tomcat.dir.rootDir} modified after date ${maven.build.timestamp} "/>
                                <copy todir="${tomcat.dir.rootDir}">
                                    <fileset dir="${project.build.directory}/${project.build.finalName}" includes="**/*">
                                        <!-- Include only recompiled files -->
                                        <date datetime="${maven.build.timestamp}" pattern="yyyy-MM-dd HH:mm:ss" when="after"/>
                                        <!-- and only *.class files -->
                                        <filename name="**/*.class"/>
                                    </fileset>
                                </copy>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
.....
.....
        </plugins>
    </build>
</project>

Then run maven with params: mvn pom.xml compile install org.apache.maven.plugins:maven-war-plugin:2.1-alpha-1:exploded

As result only changed files will be recompiled and only recompiled filed will be replaced in tomcat webapp dir.

like image 1
Oleksandr_DJ Avatar answered Oct 14 '22 01:10

Oleksandr_DJ