views:

69

answers:

3

I have a batch file that executes three Maven commands, one after the other. Each command can be successfully executed in the script - by itself!. But when I add all three commands to the same file, only the first one executes before the script exits. Any idea why?

mvn install:install-file -DgroupId=gdata -DartifactId=base -Dversion=1.0 -Dfile=gdata-base-1.0.jar  -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -DgroupId=gdata -DartifactId=blogger -Dversion=2.0 -Dfile=gdata-blogger-2.0.jar  -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -DgroupId=gdata -DartifactId=blogger-meta -Dversion=2.0 -Dfile=gdata-blogger-meta-2.0.jar  -Dpackaging=jar -DgeneratePom=true

Also, if I copy all three commands and paste them into a DOS command shell (cmd.exe), they execute one after the other with no problem. So this is apparently some issue with the dos batch file.

A: 

It should be that the particular mvn command execs and does not return, thereby not executing the rest of the commands.

Alan Haggai Alavi
Is there a way to force the script to execute the next `mvn` command?
wiki
A: 

Try writing the following batch file and executing it:

Echo one
cmd
Echo two
cmd
Echo three
cmd

Only the first two lines get executed. But if you type "exit" at the command prompt, the next two lines are processed. It's a shell loading another.

To be sure that this is not what is happening in your script, just type "exit" when the first command ends.

HTH!

belisarius
Unlikely; Maven indeed uses a batch file which is why they need to use `call`. It's not a nested shell that isn't terminated.
Joey
@Joey Thanks. That is what I guessed.
belisarius
+6  A: 

Are these maven commands like batch files, not actual compiled programs? If so, just like with batch, you call another script using the call command. Try prepending call to all commands.

Another thing you could try is using the start command. See if either of those work out for you.

Jeff M
I've put `ant` inside of windows batch files before and the `call` was required to get `ant` to execute. Without `call` the batch will stop after the first command, hence the second two not executing. http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/call.mspx for more info on `call`
Owen
`start` will cause a new window to spawn, and each of the three commands will run in parallel. If you need them to run synchronously, use `call`.
akf
`call` worked. Thank you!
wiki
@akf: The `WAIT` option for the `start` command will cause it to wait for the program to close so it doesn't necessarily have to run in parallel. I should have mentioned that in the beginning.
Jeff M