在Eclipse中运行Golang的Hello World遇到问题。

huangapple go评论95阅读模式
英文:

Issue running golang Hello World in eclipse

问题

好的,以下是翻译好的内容:

好的,所以我怀疑这个问题可能是另一个问题的重复,但我甚至不知道要搜索什么。

我以前从未使用过Eclipse或Golang,并且正在尝试让一个基本的Hello World应用程序工作。

我已经安装了goclipse插件,创建了一个新的go包和go命令源文件。根据我所读到的,在Eclipse中运行一个项目,你需要右键点击包,选择"Run as",然后设置运行配置。问题出现在当我尝试选择go包时,没有任何包显示出来,如果我将其留空,就会抛出一个"Go package not found"的异常。

谢谢你能提供的任何帮助。

编辑:根据答案的建议,我决定使用基本的命令行,但是一个朋友也推荐了LiteIDE。我会"假设"tmichels的答案在让Go在eclipse中工作方面是正确的。

英文:

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.

在Eclipse中运行Golang的Hello World遇到问题。

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.

答案1

得分: 2

如果您不使用GOPATH环境变量,并且不将项目文件夹放在$GOPATH/src下,编译器将找不到它。据我所知,goclipse允许您完全跳过GOPATH,但在这种情况下,您必须将代码放在项目资源管理器中可见的src目录下。请参阅goclipse文档的相关部分

尽管我认为使用一个功能齐全的IDE进行Go开发会让您的生活变得更加困难。只需使用命令行工具即可。这样做的额外好处是,您实际上会理解发生了什么(IDE会将这些隐藏起来)。

因此,对于构建,您可以使用go buildgo install。后者将二进制文件复制到$GOPATH/bin目录中。要运行测试,只需调用go testgo test path/to/package。在go工具中有一个隐藏的宝石:当您在同一个目录中使用多个包时,可以使用go test ./...一次性测试所有包。这对其他go命令也适用。

英文:

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.

huangapple
  • 本文由 发表于 2015年1月24日 13:00:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/28122455.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定