go开发工具goclipse的安装

(1) 安装Eclipse

建议下载Eclipse时直接下载“Eclipse IDE for Java Developers”的package,而不要下载较小的Installer。因为Installer在安装Eclipse时还要联网下载,因为科学上网的原因,联网下载会非常慢甚至失败。
Eclipse package下载地址:http://www.eclipse.org/downloads/eclipse-packages/

(2) 安装GoClipse

可以采取在线安装的方式或离线的方式安装。
我采用在线安装的方式可以安装成功,如果因为网络的原因,可选离线安装方式。
GoClipse安装指南:https://github.com/GoClipse/goclipse/blob/latest/documentation/Installation.md#installation

Start Eclipse, go to Help -> Install New Software...
Click the Add... button, then enter the Update Site URL: http://goclipse.github.io/releases/ in the Location field, click OK.
Select the recently added update site in the Work with: dropdown. Type GoClipse in the filter box. Now the Goclipse feature should appear below.
Select the GoClipse feature, make sure "Contact all update sites during install to find required software" is enabled, and complete the wizard.
Dependencies such as CDT will automatically be added during installation.

(3) 配置GoClipse

  • 在Eclipse中,打开Windows -> Preferences,找到Go,在Go installation中输入Go SDK的C:\Go目录。
    在C:\Go目录下创建一个子目录,比如work,在Eclipse GOPATH中输入C:\Go\work。


下面会在C:\Go\work这个目录下编译Go的其它工具。

  • 打开Go -> Tools。对gocode和godef可以点击Download按钮来从GitHub直接下载。


但是对guru,直接Download会失败,因为Download时试图去从Golang官网下载,而Golang官网已经被拉黑了。
不过因为Golang的代码都是托管在GitHub上的,所以我们可以通过下面的地址来下载Go tools的源代码。
https://github.com/golang/tools
下载后,在C:\Go\work\src目录下创建golang.org/x的目录结构,并将上一步git clone的Go tools的tools目录复制到golang.org/x目录下。

 git clone https://github.com/golang/tools.git

  • 在C:\Go\work\bin目录下,在命令行中执行(以GitBash为例)

export GOPATH="C:\Go\work"
go build golang.org/x/tools/cmd/guru

/c/Go/bin/go.exe build golang.org/x/tools/cmd/guru


执行命令成功后guru.exe就会生成在C:\Go\work\bin目录下。

  • 最后在Eclipse中设置好guru。

  • 在Eclipse中写第一个Go程序

    在Eclipse中新建一个Go project,再在src下创建一个hello目录,再在hello目录下新建一个hello.go的Go file。内容如下所示:


右键Run as -> Go Application。

如果出错“Executable … doesn’t exist“,请检查hello.go的第一行是否为package main,Go需要从main package作为程序入口,这一点和Java程序是不同的。

参考文章:

使用Eclipse和GoClipse作为Go开发IDE

猜你喜欢

转载自www.cnblogs.com/zouke1220/p/10070407.html