這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。
在IntelliJ IDEA14中安裝go語言外掛程式
雖然本人按照此文的步驟進行安裝,失敗了。 但是,想收藏此文。
在IntelliJ IDEA14中安裝go語言外掛程式
go語言的整合式開發環境仍不成熟,試用了liteide,感覺很不適應,快顯功能表對程式員的幹擾太大。所以就試大牌的IntelliJ IDEA,這工具本來是JAVA開發陣營的,不過它已經變為一個非常強大的支援多種語言的Integration Environment了。
1、go環境
下載Go1.5.1(由於國內偉大的牆,golang.org訪問被牆,搞點技術真是不易,從Golang中國的的百度雲端硬碟下載是不錯的選擇,http://pan.baidu.com/s/1hq1mrDM),安裝很方便,直接解壓到c:\go目錄中即可。系統PATH環境變數中加上c:\go\bin。
2、IDEA
安裝JDK1.8.0_60_x64,預設安裝在C:\Program Files\Java目錄下。安裝IDEA時需要。
安裝IntelliJ IDEA Community Edition 14.1.5到預設位置C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.1.5。
啟動IDEA程式,在設定主題時,選Skip All and Set Defaults。工具裝備就緒。
3、編譯go-lang-idea-plugin外掛程式
(不願折騰這一步的朋友到這裡下載我用1.0.0pre-release的build518編譯產生好的jar檔案:http://download.csdn.net/detail/slofslb/9182113,沒辦法有時要到CSDN下載點材料卻沒積分)
安裝外掛程式go-lang-idea-plugin,JetBrains官方的外掛程式jar檔案比較舊,所以到開源網站上找原始碼自己編譯後安裝,這個外掛程式的原始碼從這個網址下載:https://github.com/go-lang-plugin-org/go-lang-idea-plugin/releases,直接下載的原始碼master.zip中缺少idea的專案檔。我下載的是go-lang-idea-plugin--518.zip,我直接放在D:\go-lang-idea-plugin--518下。
用IDEA開啟項目,也就是d:\go-lang-idea-plugin--518目錄
此時會有git版本控制的警告,可以不管它,也可以關閉它。
此時直接編譯,會報SDK不存在,要進行幾項關鍵設定。
1)SDK設定
菜單File->Project Structure...,找到Platform Settings/SDK,點加號,加上JDK,選1.8,注意是JDK,而不是JRE,C:\Program Files\Java\jdk1.8.0_60。
再加上IntelliJ Platform Plugin SDK,就是它的安裝目錄:C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 14.1.5,Internal Java Platform綁定1.8。
再設定Project SDK: IntelliJ IDEA Community Edition IC-141.2735.5(java version 1.8.0)
2)Modules設定
此時進Project Settings/Modules的設定,應該 Module SDK使用了project SDK。
3)編譯
再編譯會有些警告,但編譯成功!!!
4)產生jar
Build->Prepare All Plugin Modules For Deployment,成功後會在d:\go-lang-idea-plugin--518目錄中產生了intellij-go.jar,我們需要的就是這一個寶貝。此時這個go-lang-idea-plugin--518項目的原始碼就編譯完成了,如果你不搞JAVA開發,以後就不用它了。
4、安裝外掛程式
進入IDEA的File->Settings->Plugin配置外掛程式,install plugin from disk...,選intellij-go.jar檔案,OK後,會提示重啟Intellij IDEA。
5、在IDEA中開發go項目
new project,項目類型選go
比如d:\goproj\hello檔案夾下,建立一個hello項目,提示你設定GO SDK,此時發現IDEA可以自動找到go1.5.1目錄了。
在project裡建立hello.go,運行時會有兩種方式,一種對應於go build後運行,一種對應於go run。
package mainimport "fmt"func main(){ fmt.Println("hello world")}
官網上給出建立idea中的go項目的方法:
https://github.com/go-lang-plugin-org/go-lang-idea-plugin/wiki/v1.0.0-Setup-initial-project
IntelliJ IDEA
- create a new project by going to Create New Project | Go and follow the setup steps
Other IDEs
- create a new blank project and you'll be prompted to setup a GO SDK for it
Once you've created the project according to your IDE, please follow the steps below
- after your project has been created, you can then add your GOPATH packages to it so that you can use all the plugin features
- to do, go to File | Settings | Languages & Frameworks | Go Libraries. Here you have a few options to choose from, but the recommended (and most tested one at the moment) is to create a new entry under Global Libraries that points to your GOPATH directory (see the example bellow). (強調要把項目主目錄加到全域庫中,可能這樣就不需要設定GOPATH了?)
- if you've followed the steps correctly, then "everything" should work for you
One concrete example would be (under Linux, paths may vary on other OSes):
- GOROOT (aka sdk home) /usr/local/go
- GOPATH (the path in Go Libraries | Global Libraries) /home/florin/golang/
- project home /home/florin/golang/src/github.com/dlsniper/misc
有人說要設定這些環境變數,但我在1.5.1中並沒有用到,直接用go.exe命令列工具時我用過GOPATH。
建立 變數名:GOBIN 變數值 :C:\Go\bin
建立 變數名:GOOS 變數值:windows
建立 變數名:GOROOT 變數值:C:\Go
建立 變數名:GOPATH 變數值:d:\goproj\hello
----==== Email: slofslb (GTD) qq.com 請將(GTD)換成@ ====----
著作權聲明:自由轉載-非商用-非衍生-保持署名(創意共用3.0許可證)
作者:申龍斌的程式人生
---- 魔方、橋牌、象棋、遊戲人生...
---- BASIC、C++、JAVA、C#、Haskell、Objective-C、Open Inventor、程式人生...
---- GTD伴我實現人生目標
---- SeismicPro地震剖面顯示程式
---- Eclipse油藏數值類比二進位檔案格式解析和格式轉換軟體