Page 1 of 1

Running Maven in the first ancestor dir that contains a pom.xml file

Posted: Wed Feb 29, 2012 7:50 pm
by dcramer
Hi there,
Our projects are use Maven and are set up such that the xml files are at various depths in a directory tree and there is a pom.xml file in a containing folder. So you might have:

project-name/pom.xml
project-name/src/docbkx/somefile.xml
project-name/src/docbkx/chapters/somechapter.xml

I'd like to set up an External Tool to kick off Maven such that it works even if you're editing somechapter.xml (i.e. a file not in the same dir as pom.xml). I thought I'd write a simple shell script that walks up the tree until it finds a pom file and then runs maven on it:

Code: Select all


while true; do [ -f pom.xml ] && break; cd ..; done; mvn clean generate-sources
I figured I could store the script in my framework and have the external tool invoke it from there, but when I try, I always get errors like:

Code: Select all


Could not start: Cannot run program "/home/dcramer/.local/share/applications/Oxygen13-2/frameworks/rackbook/test2.sh
" (in directory "/home/dcramer/Documents/rax/rackspace-template/src/docbkx"): java.io.IOException: error=2, No such file or directory
Process ended with exit code: -1234567
Is there a way to do what I want? I.e. run mvn against the pom even if the pom is in some directory above the currently edited file (and the number of levels up is an arbitrary number)?

Thanks,
David

Re: Running Maven in the first ancestor dir that contains a pom.xml file

Posted: Thu Mar 01, 2012 4:28 pm
by adrian
Hello,

When you configure the external tool in Oxygen make sure you use "/bin/sh" at the beginning of the "Command line", before the .sh script path.

e.g.
Command line:

Code: Select all

/bin/sh /home/dcramer/.local/share/applications/Oxygen13-2/frameworks/rackbook/test2.sh
Regards,
Adrian

Re: Running Maven in the first ancestor dir that contains a pom.xml file

Posted: Thu Mar 01, 2012 6:40 pm
by dcramer
That does the trick.

Thanks,
David