dongnaoben4456 2015-04-10 14:26
浏览 385

在Go中启动Java进程

I am trying to start a Java-process using Go but am unable to get Java to recognise the classpath. The code looks somewhat like:

args := []string{
  "-Xmx64m",
  "-Dmy.property=value,
  "-cp",
  "lib/jar1.jar:lib/jar2.jar",
  "com.things.MyClass",
}
c := exec.Command(javaBinary, args...)

Unfortunately when executing this I get the dreaded Error: Could not find or load main class from the JVM. However if I take the output from c.Args and run it directly in a terminal it seems to work just fine, which to me indicates that I am somehow launching the process incorrectly.

Is there a better way of doing this?

  • 写回答

1条回答 默认 最新

  • dongxin1999 2015-04-10 15:32
    关注

    Disregard this question please, the error was an extra space in the args array:

    args := []string{
      "-Xmx64m",
      "-Dmy.property=value ", //<--trailing space
      ...
    }
    

    The extra space stops further parsing from continuing leading to a missing classpath.

    评论

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料