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

WindowsMavenBatch File

Windows Problem Overview


I made a bat file like:

mvn clean;
mvn package;
but it doesn't work, only the first command is executed.

can someone help me?

Windows Solutions


Solution 1 - Windows

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 call is that mvn itself is a batch file and batch files need to call each other with call, otherwise control does not return to the caller.

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

Solution 2 - Windows

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:

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

Solution 3 - Windows

You can also have the following one-liner:

call mvn clean package 

Solution 4 - Windows

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

Solution 5 - Windows

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.

e.g call mvn clean install

Solution 6 - Windows

The observed bahaviour comes from the time of MS-DOS 1.0 and it is kept for compatibility reasons. As a solution you shall use Windows call function in the following way:

call mvn clean
call mvn package

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

Solution 7 - Windows

Use these commands in batch file to run ur script. Keep your batch file where 
you pom.xml file is housed

set ProjectPath=C:\TetonWorkSpace\PeriodicApplicationCheck
cd %ProjectPath%
mvn clean test -Dxmlfile=Smoke.xml
pause

To Create a Task in Task scheduler:
1. Follow steps as prescribed to create task
2. In the action tab, just place the path of ur batch file as shown below
    C:\TetonWorkSpace\PeriodicApplicationCheck\testng.bat
3. You can ignore the rest two options like Add Argument and Start in. Use it 
   only when there are certain conditions to be used without which the script 
    becomes dysfunctional.

Placing path of the batch file in Action Tab.

Solution 8 - Windows

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

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%

Solution 9 - Windows

Use

call mvn clean package

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrascioView Question on Stackoverflow
Solution 1 - WindowsJoeyView Answer on Stackoverflow
Solution 2 - WindowsfoupfeifferView Answer on Stackoverflow
Solution 3 - WindowscarlspringView Answer on Stackoverflow
Solution 4 - WindowsDmitri AlgazinView Answer on Stackoverflow
Solution 5 - WindowssauravView Answer on Stackoverflow
Solution 6 - WindowsSeweryn Habdank-WojewódzkiView Answer on Stackoverflow
Solution 7 - WindowsRavi ChhetriView Answer on Stackoverflow
Solution 8 - Windowsuser11404376View Answer on Stackoverflow
Solution 9 - WindowsBoobesh kumarView Answer on Stackoverflow