【问题标题】:Batch file stops executing after mvn command批处理文件在 mvn 命令后停止执行
【发布时间】:2016-10-06 03:04:19
【问题描述】:
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执行命令不明白吗?

【问题讨论】:

  • 在windows的批处理文件中你需要通过call mvn ...运行mvn和其他批处理文件...
  • 酷。 jarcopyrename 这样的命令是否相同?
  • 嗯...即使我调用它仍然不会在 mvn 命令之后直接执行1

标签: shell maven batch-file command maven-archetype


【解决方案1】:

当从批处理文件调用 Maven 以通过原型创建新项目时,您应该知道执行的 interactive mode,即 Maven 会提示某些值或要求确认。

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

来自official documentation你应该通过

  • archetypeGroupId、archetypeArtifactId 和archetypeVersion 定义了用于项目生成的原型。
  • groupId、artifactId、version和package是需要设置的主要属性。每个原型都需要这些属性。一些原型定义了其他属性;如果需要,请参阅相应原型的文档

因此在你的情况下:

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

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

【讨论】:

  • 有道理。当我用 AutoItX 编写脚本时,我可以模拟击键,但这是不同的。因此,我假设我可以在不正确的情况下将批处理文件中的命令行运行到交互式输入中。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多