2017-11-08 06:54
浏览 372


I am having the requirement of running a maven built using go lang without installing maven to the running system. With the use of os.exec package in go I am able to run any program which is already defined in my PATH variable. But setting M2_HOME in PATH variable is not an option here and I am having the maven distribution extracted in specific location. According to the answer given in here it is possible to run a maven build by providing the specific location of mvn, how do I achieve the same from go.
Thanks in advance

图片转代码服务由CSDN问答提供 功能建议

我需要运行使用 go lang < / code>,而无需将 maven 安装到正在运行的系统。 通过使用 go 中的 os.exec 包,我可以运行在 PATH 变量中已经定义的任何程序。 但是,在 PATH 变量中设置 M2_HOME 并不是这里的选择,我要在特定位置提取 maven 发行版。 根据此处中给出的答案 通过提供 mvn 的特定位置来运行 maven 构建,我如何通过 go 实现相同的功能。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dongpu8935 2017-11-10 07:33

    As with the comment by @putu and with specifying the required maven goals one by one as separate arguments to the exe.Command() I was able to run maven build without installing maven or setting M2_HOME in $PATH variable. Below is the code snippet for anyone trying to achieve the same.

    // 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
    解决 无用
    打赏 举报

相关推荐 更多相似问题