windows 如何在bat文件中执行多个maven命令?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6573062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:33:23  来源:igfitidea点击:

How to execute more than one maven command in bat file?

windowsmavenbatch-file

提问by rascio

I made a bat file like:

我制作了一个bat文件,如:

mvn clean;
mvn package;

but it doesn't work, only the first command is executed.

但它不起作用,只执行第一个命令。

can someone help me?

有人能帮我吗?

回答by Joey

Use

call mvn clean
call mvn package

Note that you don't need semicolons in batch files. And the reason why you need to use callis that mvnitself is a batch file and batch files need to call each other with call, otherwise control does not return to the caller.

请注意,批处理文件中不需要分号。而你需要使用的原因call是,mvn它本身就是一个批处理文件,批处理文件需要相互调用call,否则控制权不会返回给调用者。

If you want subsequent commands to echo to the command line (show in batch output), you must also do echo onafter the call mvnis done (on the next line). This is because mvnturns echo off and doesn't turn it back on.

如果您希望后续命令回显到命令行(在批处理输出中显示),您还必须echo oncall mvn完成后执行(在下一行)。这是因为mvn关闭回声并且不会重新打开它。

回答by foupfeiffer

Joey's answer is great, but maybe a more complete code example will help anyone else like me who's also figuring out a similar problem of building multiple maven projects from a batch file in Windows:

Joey 的回答很好,但也许一个更完整的代码示例将帮助像我这样的其他人,他们也在解决从 Windows 中的批处理文件构建多个 maven 项目的类似问题:

REM maven itself uses a batch file so each mvn must be preceded by "call"
REM the -f flag specifies where the pom.xml is found for the project
REM mvn install will save the target output to %userprofile%\.m2\repository ...

call mvn install -f c:\Users\John\workspace\PropertiesReader\pom.xml

call mvn install -f c:\Users\John\workspace\PropertiesWriter\pom.xml

回答by carlspring

You can also have the following one-liner:

您还可以使用以下单线:

call mvn clean package 

回答by Dmitri Algazin

I have more projects to run, I created such bat this:

我有更多的项目要运行,我创建了这样的蝙蝠:

@echo off
SET DEVELOPMENT_HOME=C:\Projects

cd %DEVELOPMENT_HOME%\Project1\
call mvn clean install

cd %DEVELOPMENT_HOME%\Project2\
call mvn clean install

回答by saurav

Use 'call' when you want to invoke another batch file in the parent file ,so that control will be returned to the parent batch file and it will continue execution.

当你想调用父文件中的另一个批处理文件时使用'call',这样控制将返回到父批处理文件并继续执行。

e.g call mvn clean install

例如调用 mvn clean install

回答by Seweryn Habdank-Wojewódzki

The observed bahaviour comes from the time of MS-DOS 1.0 and is keep for compatibility reasons, as solutions you shall use Windows callfunction in the following way:

观察到的行为来自 MS-DOS 1.0 时代,出于兼容性原因保留,作为解决方案,您应按以下方式使用 Windows调用函数:

call mvn clean
call mvn package

The "call" executes one batch program from another and interprets it as subroutine.

“调用”从另一个执行一个批处理程序并将其解释为子程序。

回答by user11404376

we can use the following to build a maven and pass it to any unix folder for development purpose

我们可以使用以下内容来构建一个 Maven 并将其传递到任何 unix 文件夹以用于开发目的

SET projectName=commonutil
cd %gitpath%\%projectName%
call mvn clean install -DskipTests=true %password%
IF %ERRORLEVEL% EQU 0 (Echo No error found) ELSE goto exitdoor 
SET jarpath="%gitpath%\%projectName%\target\%projectName%-0.0.1-SNAPSHOT.jar"
copy /Y %jarpath% "%libpath%"
scpg3 %jarpath% %ssh_profile_name%@%hostname%:%dev_lib_folder_name%

回答by Boobesh kumar

Use

call mvn clean package

称呼 mvn clean package

sample
------
echo %test%
cd %test%\ManaulActionAddNotes-test
call mvn clean
cd %test%\restAuthentication-test
call mvn clean