批处理文件在 mvn 命令后停止执行

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

到这里一切正常,然后命令行停止执行。它不打印 1,也不打印后续命令。

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

问题:关于maven有什么我不知道的会中断批处理吗?单号1执行命令不明白吗?

当从批处理文件中调用Maven通过archetype创建新项目时,您应该注意执行的interactive mode,即Maven会提示输入某些值或要求确认。

在您的情况下,这似乎不是期望的行为。因此,您应该通过命令行传递 generate 目标的一些 options 和特定原型,然后 运行 通过 -B 标准 Maven 选项以批处理模式或通过 -DinteractiveMode=true.

official documentation开始你应该通过

  • 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

因此在你的情况下:

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

注意:\为了便于阅读而添加,您实际上并不需要它