Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

What does %1 do in batch?

When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.

What is batch mode in Maven?

Sep 17, 2014 at 17:03. 2. Interactive means you need to type some answer in your keyboard and batch mode means no need to type anything maven is assuming defaults as answers.


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.


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

You can also have the following one-liner:

call mvn clean package 

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