我需要运行使用go lang构建的go lang,而不将maven安装到运行系统中。通过在os.exec中使用go包,我能够运行已经在go变量中定义的任何程序。但是,在M2_HOME变量中设置PATH并不是一个选项,而是在特定位置提取maven分布。根据here中给出的答案,可以通过提供mvn的特定位置来运行maven构建,如何从go中实现相同的目标。
提前感谢
发布于 2017-11-10 07:33:45
与@putu的注释一样,通过将所需的maven目标逐一指定为exe.Command()的独立参数,我能够在不安装maven或在$PATH变量中设置M2_HOME的情况下运行maven构建。下面是任何试图实现相同目标的人的代码片段。
// Use os package to run the maven build using location where maven(headless) resides
func updateDistribution() error {
command := exec.Command("apache-maven-3.5.2/bin/mvn", "clean", "install")
command.Dir = "."
output, err := command.Output()
if err != nil {
return err
}
fmt.Printf("%s", output)
return nil
}https://stackoverflow.com/questions/47173361
复制相似问题