shellmavenbatch-filecommandmaven-archetype

Batch file stops executing after mvn command


set homepath=%userprofile%
set a=%1
set b=%2
set c=%3
set uuid=%4
set zipDirectory=%5
set pluginDirectory=%6
cd %homepath%\%a%
mvn archetype:generate -DarchetypeCatalog=file://%homepath%/.m2/repository

Everything works up to here, then the command lines stop executing. It doesn't print the 1, nor subsequent commands.

1
c
b
c
%uuid%
Y
cd %homepath%\%a%\%b%
mvn clean install
cd %homepath%\%a%\%b%\%b%-plugin\target
jar -xvf %zipDirectory%
cd %homepath%\%a%\%b%\%b%-plugin\target\META-INF\maven\%c%\%b%-plugin
copy pom.xml + %pluginDirectory%
cd %pluginDirectory%
rename pom.xml %b%-plugin-1.0.0.pom

Question: Is there anything about maven I don't know about that interrupts a batch process? Does it not understand to execute the command with a lone number 1?


Solution

  • When invoking Maven from a batch file to create a new project via archetype you should be aware of the interactive mode of the execution, that is, Maven will prompt for certain values or ask for confirmation.

    It seems in your case this is not the desired behavior. You should hence pass via command line some options of the generate goal and the specific archetype and then run either in batch mode via the -B standard Maven option or via -DinteractiveMode=true.

    From official documentation you should pass

    • The archetypeGroupId, archetypeArtifactId and archetypeVersion defines the archetype to use for project generation.
    • The groupId, artifactId, version and package are the main properties to be set. Each archetype require these properties. Some archetypes define other properties; refer to the appropriate archetype's documentation if needed

    Hence in your case:

    call mvn archetype:generate -DarchetypeCatalog=file://%homepath%/.m2/repository -B \
    -DarchetypeGroupId=com.sample -DarchetypeArtifactId=artifact -DarchetypeVersion=1.0 \ 
    -DgroupId=your.groupid -DartifactId=your.artifactId -Dversion=0.0.1-SNAPSHOT \
    -Dsomething-else=value
    

    Note: \ added for readability, you don't actually need it