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

前端 未结 4 936
忘掉有多难
忘掉有多难 2020-12-02 05:37

Supposing my maven project is located in /some/location/project and my current location is /another/location/ how can I run maven build without cha

相关标签:
4条回答
  • 2020-12-02 06:06

    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

    0 讨论(0)
  • 2020-12-02 06:15

    You can try this:

    pushd ../
    maven install [...]
    popd
    
    0 讨论(0)
  • 2020-12-02 06:16

    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.

    0 讨论(0)
  • 2020-12-02 06:20

    For me, works this way: mvn -f /path/to/pom.xml [goals]

    0 讨论(0)
提交回复
热议问题