Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Maven from another directory (without cd to project dir)?

Tags:

maven

Supposing my maven project is located in /some/location/project and my current location is /another/location/ how can I run maven build without changing to project location cd /some/location/project?

like image 318
Ali Shakiba Avatar asked Jun 25 '11 14:06

Ali Shakiba


People also ask

How do I run a Maven project with an E switch?

Right click your project and Run as -> Run Configurations... Add the -e (or other switches for eg. -X, etc.) in the Goals input box.


2 Answers

You can use the parameter -f (or --file) and specify the path to your pom file, e.g. mvn -f /path/to/pom.xml

This runs maven "as if" it were in /path/to for the working directory.

like image 177
dunni Avatar answered Sep 28 '22 19:09

dunni


I don't think maven supports this. If you're on Unix, and don't want to leave your current directory, you could use a small shell script, a shell function, or just a sub-shell:

user@host ~/project$ (cd ~/some/location; mvn install) [ ... mvn build ... ] user@host ~/project$ 

As a bash function (which you could add to your ~/.bashrc):

function mvn-there() {   DIR="$1"   shift   (cd $DIR; mvn "$@")      }   user@host ~/project$ mvn-there ~/some/location install) [ ... mvn build ... ] user@host ~/project$ 

I realize this doesn't answer the specific question, but may provide you with what you're after. I'm not familiar with the Windows shell, though you should be able to reach a similar solution there as well.

Regards

like image 25
Kyle Burton Avatar answered Sep 28 '22 19:09

Kyle Burton