Sunday, February 3, 2013

How to write a batch script to run multiple maven command line in Window?

This happened when the developer wish to prepare a batch script for others developer to manually install the third party jar file to the local repository. This is not a problem if only 1 command line is required to be executed in the batch file, for example

mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code -DartifactId=kaptcha -Dversion={version} -Dpackaging=jar
If the developer wish to run multiple mvn command line as shown below, then only first mvn command line will be getting executed and first jar file is getting installed in the local repository.

mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code -DartifactId=kaptcha -Dversion={version} -Dpackaging=jar

mvn install:install-file -DgroupId=com.google.gdata -DartifactId=gdata-client -Dversion=1.0 -Dpackaging=jar -Dfile=c:\gdata-client-1.0.jar
If we wish to get all the command line get executed, put the "call" in front of each of the command and your batch file will be looked like below 
call mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code -DartifactId=kaptcha -Dversion={version} -Dpackaging=jar

call mvn install:install-file -DgroupId=com.google.gdata -DartifactId=gdata-client -Dversion=1.0 -Dpackaging=jar -Dfile=c:\gdata-client-1.0.jar
Voila, you will get all the jar files installed in your local repository.

No comments: