Fixing the output of mvn eclipse:eclipse for Sling


I tend to use Eclipse only for editing/navigating code and for remote debugging, leaving the heavy lifting of building and executing stuff to the old trusted command line.

In this context, the mvn eclipse:eclipse plugin often generates too much magic for me. When working with Sling, especially, I don't want any maven or java builders in my Eclipse projects, and for some reason the plugin generates an extra resource path based on the LICENSE, NOTICE and similar files.

If you like to work in the same way (I know many people like go further with their IDEs), here are two scripts that I use to post-process the Eclipse project files after mvn eclipse:eclipse.

This scripts "fixes" all .project and .classpath files under the current directory (uses xsltproc):

XSLT=$(dirname $0)/fix-eclipse-maven.xsl

find . -name .project | while read p
echo "Running $(basename $XSLT) on $p..."
xsltproc $XSLT $p > $TMPF
rm -f $p
mv $TMPF $p

find . -name .classpath | while read c
echo "Removing lines containing $EXPR from $c)"
grep -v $EXPR $c > $TMPF
rm -f $c
mv $TMPF $c

And uses this XSLT transform to get rid of the build commands in .project files:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"

<xsl:template match="\*">
<xsl:copy-of select="@\*"/>

<!-- remove all Eclipse buildCommands -->
<xsl:template match="buildCommand"/>