Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute multiple maven project from MS bat file?

Tags:

I need to build 3 independent maven projects using a build.bat file (because of tycho aggregation is not an option - see comments on romaintaz answer). I have tried (executed from the build folder - see below):

cd ../projectA mvn clean install -U cd .. cd ../projectB mvn clean install -U cd .. cd ../projectC mvn clean install -U 

where the folder structure of the projects are:

build   |--> build.bat  projectA   |--> pom.xml  projectB   |--> pom.xml  projectC   |--> pom.xml 

but only projectA is build projectB and projectC are skipped. Any ideas on how to modify the above batfile so the following project is build if the previous was build successfully?

like image 534
u123 Avatar asked May 25 '11 20:05

u123


People also ask

How do I run a maven project in a batch file?

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.

Where can I find maven bat?

bat file at the 'C:\apache-maven-3.3. 9\bin' location.


2 Answers

Use the call command to execute your mvn processes, like:

call mvn clean install -U 

See online doc for call or

help call 

for further explanations on the call command.

To avoid having all these cd commands you can also use the -f option to specify the path to your pom, e.g.

call mvn -f <path>/projectA/pom.xml clean install -U call mvn -f <path>/projectB/pom.xml clean install -U call mvn -f <path>/projectC/pom.xml clean install -U 
like image 159
FrVaBe Avatar answered Oct 01 '22 19:10

FrVaBe


As noted above, you need to use "call" to run mvn script as in:

call mvn package 

In order to catch errors you need to use the ERROR_LEVEL variable as in:

call mvn clean echo Exit Code = %ERRORLEVEL% if not "%ERRORLEVEL%" == "0" exit /b 

See http://jojovedder.blogspot.com/2009/03/executing-multiple-mvn-commands-from.html for further comments.

like image 24
Martin Modrák Avatar answered Oct 01 '22 18:10

Martin Modrák