2

Alright, so just a disclaimer I suspect this question will be a duplicate of another question however I'm not even sure what to search for.

I have never used Eclipse or Golang before and am attempting to get a basic hello world application to work.

I have installed the goclipse plugin, created a new go package and go command source file. From what I have read to run a project in Eclipse you right click the package, select Run as then set the run configurations. The problem occurs when I attempt to select the go package as none shows up and if I leave it blank it throws a 'Go package not found' exception.

enter image description here

Thank you for any help you can provide.

EDIT: Upon the answers advice I have decided to go with the basic command line, however a friend did also recommend LiteIDE. I will "assume" tmichels answer is correct in regards to getting Go to work within eclipse.

Adrian773
  • 473
  • 11
  • 22
  • 2
    There is no need to run a Go program from your IDE: The command line works fine for Go code. Go is not Java where manually crafting a classpath is for masochists only. – Volker Jan 24 '15 at 10:35

1 Answers1

2

If you don't use the GOPATH environment variable and you don't put your project folder under $GOPATH/src the compiler won't find it. As I see it goclipse lets you skip the GOPATH entirely but in this case you have to put your code under the src directory that you can see in the Project Explorer. See the related section of the goclipe documentation.

Although I think you make your life harder by using a full-fetched IDE for go development. Just use the command line tools. And it has the added benefit that you will actually understand what's going on (IDEs hide this from you).

So for building you can use go build or go install. The latter will copy the binary to your $GOPATH/bin directory. For running test just call go test or go test path/to/package. There is a hidden gem in the go tool: when you are working with multiple packages in the same directory you can use go test ./... to test all of them at once. This also works with other go commands.

tmichel
  • 954
  • 7
  • 7
  • Not all IDEs hide how the command-line tools work, and in particular, Goclipse doesn't. But then this means one needs to understand how the command-line tools work, to work with Goclipse effectively. That's why the example above didn't work - the go source is not in a layout that the go tools understand: to use go build with "./...", then the .go files must be in a subfolder of `src/`. The documentation has been updated to clarify this: https://github.com/GoClipse/goclipse/blob/latest/documentation/UserGuide.md#project-structure (admittedly the IDE could do a better job of warning the user) – BrunoMedeiros Jan 27 '15 at 13:54