Anvar
Anvar

Reputation: 1280

Starting a Java-process in Go

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?

Upvotes: 1

Views: 66

Answers (1)

Anvar
Anvar

Reputation: 1280

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.

Upvotes: 1

Related Questions