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
?
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.
./path/pom.xml
–
Pellmell pom.xml
, rather than pom.xml
itself. In other words, for the given example, mvn -f /path/to
and mvn -f /path/to/pom.xml
behave the same way. (Using Maven 3.5.4. Admittedly, this might not have been the case when the answer was written.) –
Tadio -f
switch is --file
(see here and here). Wanted to mention it because apparently that hasn't always been the case. –
Tadio evaluateBeanshell
rule and evaluate something like System.out.println(new File(".").getAbsolutePath());
there before returning true
, then you see it on the console. Soif you have any plugin actions somehow depending on the current directory (due to poor implementation), better cd
into the directory housing the POM first. –
Calcifuge For me, works this way: mvn -f /path/to/pom.xml [goals]
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
You can try this:
pushd ../
maven install [...]
popd
If you want to run maven without this command "mvn -f path/to/pom.xml" you can right click on your folder project (in intellij) and click on Rebuild module "name of your artifactId" (corresponding in your pom.xml). It worked for me.
© 2022 - 2024 — McMap. All rights reserved.