1

As much as I know, Maven compiles only modified files and copy them into target folder.

In my webapp folder, there're lots of files over the size of 800MB.

When I launch this command ( mvn package ).

This takes more than 10 minutes to copy all resources into target/icall/

[INFO] Copying webapp resources [/data1/workspace/icall/src/main/webapp]

This makes me annoyed.

Is there a way to copy only modified files or newly generated files??

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.byto</groupId>
    <artifactId>icall</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>icall Maven Webapp</name>
    <url>http://maven.apache.org</url>

    <build>
        <finalName>icall</finalName>

        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <escapeString>\</escapeString>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.7</version>
                <configuration>
                    <additionalProjectnatures>
                        <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
                    </additionalProjectnatures>
                    <additionalBuildcommands>
                        <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
                    </additionalBuildcommands>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                    <wtpversion>1.5</wtpversion>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <profiles>
        <!-- Unrelated Profiles -->
    </profiles>

    <properties>
        <spring-version>3.1.1.RELEASE</spring-version>
        <tiles-version>2.2.2</tiles-version>
        <mybatis-version>3.1.1</mybatis-version>
    </properties>

    <dependencies>
         <!-- Lots of Unrelated Dependencies -->
    </dependencies>

</project>

Here's linux bash file that I use instead of Package or Install goal. But I cannot use Dependency Management which is maven's main feature. but this is still good for me.

#! /bin/sh

tomcat_path=/usr/local/tomcat
source_path=/data1/workspace/icall
deploy_path=/data1/icall_root

function refresh_source {
    # Update source from SVN
    echo -e "\n\n** Getting new sources from SVN." &&
    svn update &&

    # Compile *.java
    echo -e "\n\n** Building *.java with Maven." &&
    mvn compile -Pdev &&

    # Copy only modified files
    echo -e "\n\n** copying files from ${source_path}/src/main/webapp to ${deploy_path}." &&
    rsync -av --exclude=.svn --exclude=WEB-INF/lib/* --exclude=WEB-INF/classes/* --delete ${source_path}/src/main/webapp/* ${deploy_path}/ &&

    echo -e "\n\n** copying files from ${source_path}/library to ${deploy_path}/WEB-INF/lib." &&
    rsync -av --delete --delete-excluded ${source_path}/library/* ${deploy_path}/WEB-INF/lib/ &&

    echo -e "\n\n** copying files from ${source_path}/target/classes/ to ${deploy_path}/WEB-INF/classes/"
    rsync -av --checksum --delete --delete-excluded ${source_path}/target/classes/* ${deploy_path}/WEB-INF/classes/ &&

    ## Only for development server
    cp -f ${deploy_path}/info.jsp ${deploy_path}/data/info.jsp
}

function tomcat_restart {
        ${tomcat_path}/bin/shutdown.sh &&
        sleep 30 &&
        ${tomcat_path}/bin/startup.sh
}

case "$1" in
    restart)
        refresh_source &&
        tomcat_restart
        ;;
    log)
        tail -f ${tomcat_path}/logs/catalina.out
        ;;
    *)
        refresh_source
        ;;
esac
Patrick Jeon
  • 1,684
  • 5
  • 24
  • 31

2 Answers2

0

You could create an extra artifact, which does only contain those large resource files. The artifact will only reside in your local repository during pre-package phases. You can't avoid the copying during the package phase, if you need to put that artifact in a war file, for example. However you could try to not put this in the war and leave it as another file, which should be extra on the classpath. But this might lead to more complex deployment scenarios.

SpaceTrucker
  • 13,377
  • 6
  • 60
  • 99
  • Thank you. Actually, I've given up using maven to build whole package. Instead, I use 'rsync' in linux to copy modified files. but the weakness is that I cannot use dependency management since Maven doesn't support the copy of library files without package or install goals. – Patrick Jeon Aug 08 '12 at 00:28
  • This doesn't sound very maintainable to me. The maven dependency plugin has a [copy-dependencies goal](http://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html). Maybe you can use that. You should have very good reasons for making exceptions in your build process. And at the moment I don't see such one. – SpaceTrucker Aug 08 '12 at 11:15
0

I've found that excluding the files that were not needed in the final war speeds up the build. See also this answer https://stackoverflow.com/a/41452761/225341

Community
  • 1
  • 1
Victor Ionescu
  • 1,967
  • 2
  • 21
  • 24