I've recently bought an Intel 520 SSD, so my top priority for my laptop is to reduce the disk write during daily use. In the Java world, Maven is one of the most common build tool out there. My most used Maven command is:

mvn clean package

This command will do a fresh build of the project, then copy all the compiled classes/resources to the build directory of Maven (which is the folder 'target', next to your source directory). If you have a large Maven project at hand, this command will perform thousands disk write (clean compiled classes and resources, then compile Java classes and assemble the resources into WAR/JAR file). By changing the build directory of Maven to /tmp (which is a tmpfs mountpoint (residing on RAM on my ArchLinux)), I can now rebuild my project as many times as I like without the write amplication concern. Here is now I do it in Maven:

  • Define a property name target.directory with the default value is target
  • Under the build section in your POM file, add this tag <directory>${target.directory}</directory>
  • Modify your settings.xml file to include this snippet in your active profile:
    
        /tmp/maven/${project.groupId}-${project.artifactId}/target
    
    
With the above configuration, maven will do all the build in /tmp, my SSD will thanks me for this :), but we have a small problem! Eclipse does not allow the build directory to be located outside the project directory, but I have a workaround for that. By defining a linked resource, Eclipse will happily with our setup! Here is the complete sample pom.xml file:

 4.0.0
 com.abc
 abc
 war
 1.0
 Sampe Webapp
 http://www.abc.com
 
  target
 
   
  
   junit
   junit
   3.8.1
   test
  
 
 
  abc
  ${target.directory}  
 
 
   
     maven-eclipse-plugin
       2.8
       
         true
         true
         target
         
           
             target
             2
             ${project.build.outputDirectory}
           
         
       
   
 

And the sample settings.xml file:

  
  
    
      development
      
        /tmp/maven/${project.groupId}-${project.artifactId}/target
       
    
    
      public-snapshots      
  
  
    development
  

Happy coding!

1 comments:

Anonymous on January 7, 2014 at 1:15 PM

Thanks a lot, that was useful=)

Post a Comment