Cap*_*Man 6 python batch-file maven
(我正在使用 Windows。)
我正在尝试从 python 脚本运行 maven。我有这个:
import subprocess
mvn="C:\\_home\\apache-maven-2.2.1\\bin\\mvn.bat --version"
p = subprocess.Popen(mvn, shell=True, stdout = subprocess.PIPE)
stdout, stderr = p.communicate()
print p.returncode # is 0 if success
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我想知道以下几点:
我想要实现的长期目标(如果有人有更好的方法,我会注意到这一点)是制作一个简单的脚本来构建项目列表并将另一个文件列表(罐子/其他修改过的东西)移动到要部署的文件夹中对于虚拟机,手动操作是一件非常痛苦的事情。我毫不费力地在批处理脚本中工作,我只是想学习 Python 并想知道它是否更容易管理,因为我可以制作几个列表并遍历每个位置而不是一行批处理脚本中的每个任务。
(我的批处理脚本的简短版本。)
@set version=7.8.3
@set staging_folder=C:\Users\me\Desktop\staging
@set stage_was=%staging_folder%\was
@set stage_ear=%stage_was%\stuffui.ear
@set stage_war=%stage_ear%\stuff-%version%.war
:: delete stage contents
call del /s /q %staging_folder%
call rmdir /s /q %stage_was%
:: make folders
call mkdir %stage_ear%
call mkdir %stage_war%\WEB-INF\lib
:: maven builds
call mvn -f C:\workspace\pom.xml -pl proj1,proj2 clean install
:: copy to stage
call xcopy C:\workspace\proj1\target\thing1.jar %stage_ear%\ /i /y
call xcopy C:\workspace\proj2\target\thing2.jar %stage_ear%\ /i /y
call xcopy C:\workspace\proj2\target\thing2.jar %stage_war%\WEB-INF\lib\ /i /y
Run Code Online (Sandbox Code Playgroud)
Mark 对Accessing Java API information with Python的回答提到:
Jython是在 Java VM 上运行的 Python。
请参阅我的答案,了解有关如何使用 Maven Invoker(在本例中从 Java 内部)的示例。