如何在安装了goclipse的eclipse中运行GO项目

蒂娜:

我已经在eclipse中安装了goclipse并创建了一个新的go项目。

现在这就是我所拥有的:

在此处输入图片说明

我有hello.go看起来像这样:

package main

import "fmt"

func main() {
     fmt.Println("Hello")
}

然后,我按下运行按钮,或右键单击文件hello.go,然后运行,它什么也没有。此外,它在bin文件夹中也为空。

然后我按下run configurations按钮,那里只有一个项目名称,几乎是空的。它给:

Given Go package not found.

这是我的Go偏好设置: 在此处输入图片说明

我注意到GOROOT和GOPATH都与资源管理器中列出的不同,但是一旦将它们更改为C:\ Go \ src \ pkg或C:\ Go \ src,“应用和确定”按钮将被禁用。此外,我也没有C:\ Go \ src \ pkg文件夹。

I can go install or go build in command line, but I would like to use eclipse for another much larger project. It's windows 7, and the eclipse version is Luna Service Release 1 (4.4.1). Thank you.

EDIT: Now I have the following configurations, and it works fine: Go is installed at c:\Go in Preferences: GOROOT:C:\Go, GOPATH: C:\Users\Tiina\go_workspace The rest in Preferences is filled in automatically. helloTest project is located at C:\Users\Tiina\go_workspace\src\helloTest hello.go is located at C:\Users\Tiina\go_workspace\src\helloTest\hello.go Maybe because I create a project from existing code, and there was something left behind, it automatically adds another GOPATH, in Preferences delete it.

VonC :

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:

项目位置不属于任何GOPATH条目。
在这种情况下,项目位置将隐式添加为一个条目的GOPATH,和去工作空间结构的binpkgsrc目录将在项目中使用。

请注意,项目的隐式GOPATH条目仅适用于该项目中的源模块。其他Goclipse项目将看不到它(除非该条目已显式添加到global中GOPATH)。

在该src文件夹中,您可以创建Go源文件,这些源文件将被编译成一个库包(放入pkg)或可执行文件(放入bin)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在GoClipse中设置Go

如何在Eclipse中运行Play项目

如何在安装了 PHP v8.1 的计算机上运行 Laravel 5 项目

如何在m2e中配置工具链插件/在Eclipse中安装了maven

如何在Chrome中运行Eclipse的动态Web项目?

如何在 eclipse neon 2 中运行 java 7 项目?

如何在Eclipse中运行/调试Java Web Service项目

如何在Eclipse IDE中运行Jupyter Notebook项目

如何安装较旧的Goclipse版本?无法在Eclipse 4.5.2(Mars.2)上安装Goclipse 16.1

如何在GoClipse中交叉引用?

如何在GoClipse中启用自动导入?

如何在Go服务器上运行GO项目?

Eclipse中如何在Intellij中的码头上运行Maven项目?

如何在安装了 WordPress 的域上运行单独的 PHP 代码?

如何在安装了Nginx的情况下运行Docker容器?

如何在安装了所有更新的 Ubuntu 16.04 LTS 上运行 Scilab 5.5.2?

为德语安装了Babel。现在,在Eclipse中运行的应用程序是德语,但导出为“ Eclipse产品”仍为英语

如何在Eclipse中运行具有main()的单个Java文件,而不创建整个Java项目?

如何在Android的AIDE中运行基于gradle的Libgdx eclipse项目?

如何在Eclipse中备份Java项目?

如何在Eclipse中链接项目

如何在Eclipse中合并项目?

如何在Eclipse中安装tomcat插件

如何在Eclipse中安装Hibernate

如何在Eclipse中“安装” Simple?

如何在16.04中安装Eclipse光子?

如何在Alpine Linux中安装Go

当我已经安装了 python 3.6 时,如何在运行 python(和 pipenv)2.7 的 pycharm 中设置虚拟环境?

如何识别在Eclipse IDE中安装了哪个SVN插件