我想將 maven 的本地存盤庫路徑讀入批處理腳本中的變數。
當試圖通過控制臺檢索路徑時,它作業正常:
C:\Users\me>mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout
C:\Users\me\.m2\repository
但是,當在批處理檔案的 for-in 回圈中運行相同的程式時,它會引發 MissingProjectException。
C:\Users\me>FOR /F "tokens=*" %%g IN ('mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout') do (SET LOCAL_REPO=%%g)
C:\Users\me>(SET LOCAL_REPO=[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (C:\Users\me). Please verify you invoked Maven from the correct directory. -> [Help 1] )
C:\Users\me>(SET LOCAL_REPO=[ERROR] )
C:\Users\me>(SET LOCAL_REPO=[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. )
C:\Users\me>(SET LOCAL_REPO=[ERROR] Re-run Maven using the -X switch to enable full debug logging. )
C:\Users\me>(SET LOCAL_REPO=[ERROR] )
C:\Users\me>(SET LOCAL_REPO=[ERROR] For more information about the errors and possible solutions, please read the following articles: )
C:\Users\me>(SET LOCAL_REPO=[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException )
我假設它沒有正確解釋這里的命令(可能是因為冒號?),但我不知道我做錯了什么。任何幫助是極大的贊賞 :)
uj5u.com熱心網友回復:
FOR /F "tokens=*" %%g IN ('mvn help:evaluate "-Dexpression=settings.localRepository" -q -DforceStdout') do (SET LOCAL_REPO=%%g)
-Dexpression 標志需要放在引號中,否則它會被拆分,并且 'settings.localRepository' 被視為生命周期階段。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/466107.html
