How to run a GO project in eclipse with goclipse installed

If GOROOT refers to where go is installed (C:\Go), then you need to make sure that:

  • GOPATH differs from GOROOT (it is important, because GOROOT/[src|pkg|bin] are folders for the Go language itself, not for your own sources)
  • GOPPATH points to a folder under which all your different Go project will reside (for instance C:\Users\yourName\Go: that defines a workspace)
  • your eclipse project is created in GOPATH\src\myproject

See "How to Write Go Code" to make sure that your installation and project sources respect the expected organization.


The OP Tiina reports in the comments:

Now it works, but I noticed two things odd.

  • First what I did: I move helloTest folder into C:\Users\Tiina\go_workspace\src, so now it is at C:\Users\Tiina\go_workspace\src\helloTest.
  • Then I create project from existing code. Nothing else changed. Now I have two GOPATH in explorer, one is C:\Users\Tiina\go_workspace\src, the other one is C:\Users\Tiina\go_workspace\helloTest\src.
    The latter one did no exist at the beginning

I suspect what goclipse does is define one GOPATH per project (or complete the existing GOPATH).
If you create or import a project, it will define/complete GOPATH in <that project/src>
If you hello.go is within that <that project/src/> folder, then it should build and work as expected.

The user guide "project structure" of goclipse mentions:

The project location is not part of any GOPATH entry.
In this case the project location will implicitly be added as an entry to the GOPATH, and a Go workspace structure with the bin, pkg, and src directories will be used in the project.

Note that the project's implicit GOPATH entry will only apply to the source modules in that project. It will not be visible to other Goclipse projects (unless the entry is explicitly added to the global GOPATH).

In the src folder you can create Go source files that will be compiled into a library package (and placed into pkg), or into an executable (and placed in bin)


Here's what one needs to do. One must always follow GO's convention of the directory structure. In eclipse, once a new project is created just create a "new folder" under the src directory by right clicking on the src folder. And now underneath this folder create a new GO file. I had issues running this on my MAC but by following the above steps was able to resolve.

  • Vishal (www.vishalpandya.com)