Golang on eclipse: "Resource doesn't have a corresponding Go package" on Mac - eclipse

As stated in the title, I have a problem running the Golang code on Eclipse. I'm currently using Mac, and I installed go by using homebrew.
Currently, the folder where go is installed is as follows.
/usr/local/Cellar/go/1.5.2/..
and after running Terminal and typing open ~/.bash_profile I added the following.
export GOROOT="/usr/local/Cellar/go/1.5.2/"
export PATH=$PATH:$GOROOT/bin
Am I still missing something else?
PS If I run the code using Terminal like go run main.go, I have absolutely no problem. The problem must be due to some misconfiguration in Eclipse.

I had the same error. Putting the source file under a sub-folder in src fixed it.

Go to 'Run Configurations' -> Filter with Go Application -> select your project and then click the Environment tab, then click on select button and tick the GOPATH environment. select apply and then Run.

I had the same problem and I did two things to solve it:
I opened Run configurations, filtered using "Go" and created a new configuration (right click on "Go Application" as a result of the filter). In the Environment tab added a new variable: GOPATH = [path to your workspace].
I had .go files right under src folder, and this is wrong. I created a folder under src folder and moved .go files to that folder.
The first step could be replaced by creating a system environment and adding it to the list using the "Select" option instead of creating a new one. I prefered to create a new one so I can run differente projects in the same laptop without having to change the value of the system environment.

Because the executable path is not right.
GoClipse compiles source into $project/bin, so we must set GOPATH = $project
Select project > Alt+Enter > Go Compiler > Use project specific settings > Eclipse GOPATH
In my case of wiki tutorial, GOPATH = :/home/sovann/go/wiki.
Then the IDE is able to locate /home/sovann/go/wiki/bin/main

Related

Go language configuring

I need to do a work for my university and I choose to do it using the Go language. Yesterday I installed the .msi and setted the variables to:
GOPATH = C:\Users\Gustavo\goprojects (this is the folder that I want to place all my Go projects)
GOROOT = C:\Go\
PATH = C:\Users\Gustavo\goprojects\bin
After this, I installed the GoClipse plugin on my Eclipse and created a new project into the goprojects folder. Then, I created another folder in the src folder, and a .go file into this folder.
Now is my problem. When I started to write some code, everytime that I try to auto complete my code, Eclipse shows me an error and I was searching on google and found that I need to install one project from GitHub called gocode.
So I want to know where do I need to install it and how can I import it to my project.
P.S.: I am using Windows 8.1, I have git installed and the link of gocode project is: https://github.com/nsf/gocode
I solved my problem doing this steps:
Downloaded the gocode to the src folder. (The path: C:\Users\Gustavo\goprojects\src\github.com\nsf\gocode)
In the Eclipse, do this: Window -> Preferences.
Open Go option in the left menu then click Tools.
In the gocode path I set C:\Users\Gustavo\goprojects\bin\gocode.exe
And thats it! It works now.

How to run a GO project in eclipse with goclipse installed

I have installed goclipse in my eclipse and created a new go project.
Now this is what I have:
And I have hello.go looks like this:
package main
import "fmt"
func main() {
fmt.Println("Hello")
}
Then I press run button, or right click the file hello.go, and then run, it gives nothing. Besides, it is also empty in bin folder.
Then I press run configurations button, almost empty there with only a project name. it gives:
Given Go package not found.
This is my Preferences for Go:
I noticed that both GOROOT and GOPATH are different from those listed in explorer, but once I changed them to C:\Go\src\pkg or C:\Go\src, the Apply and OK button becomes disabled. Besides, I don't have C:\Go\src\pkg folder either.
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.
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)
Please respect the fact, that if you change GOPATH while working in Eclise/GoClipse, you will have to Quit/restart Eclipse in order to Eclipse have the new environment variables to be reread.

How to change the Eclipse default workspace?

Where can I change the default workspace in Eclipse?
If you mean "change workspace" go to File -> Switch Workspace
I took this question to mean how can you change the Default workspace so that when Eclipse boots up the workspace you want is automatically loaded:
Go under preferences then type "workspace" in the search box provided to filter the list. Alternatively you can go to General>Startup and Shutdown>Workspaces.
There you can set a flag to make Eclipse prompt you to select a workspace at startup by checking the "Prompt for workspace at startup" checkbox.
You can set the number of previous workspaces to remember also. Finally there is a list of recent workspaces. If you just remove all but the one you want Eclipse will automatically startup with that workspace.
Go to eclipse\configuration\
Open the file "config.ini"
Modify the line
osgi.instance.area.default="F:/Workspace/Java"
where "F:/Workspace/Java" should be your default workspace!
If you are talking about changing the working directory for a java program that you launch from within eclipse, then there's a space for that in the run configuration.
If you go to Run menu and select "Run Configurations..." then select your run configuration, then on the "Arguments" tab for a Java Application there is a place for you to edit the "Working directory". This alters the current directory that will be used for launching the java program.
See related question Default eclipse working directory if this is what you are meaning.
Whatever Frank has suggested to change in config.ini is correct. In case, if that didn't help, you need to remove path from recent workspace as below.
Go to eclipse\configuration\org.eclipse.ui.ide.prefs\
Open the file "org.eclipse.ui.ide.prefs"
Remove the first path in RECENT_WORKSPACES.
MAX_RECENT_WORKSPACES=5
RECENT_WORKSPACES=/Users/wrokspace1\n/Users/wrokspace2\n/Users/wrokspace3\n/Users/wrokspace4
RECENT_WORKSPACES_PROTOCOL=3
SHOW_WORKSPACE_SELECTION_DIALOG=false
eclipse.preferences.version=1
File > Switch workspace > add the workspace you like > Eclipse will restart using the workspace you wanted.
If you mean to change the directory in which the program execution will occur, go to "Run configurations" in the Run tab.
Then select your project and go to the "Arguments" tab, you can change the directory there. By default it is the root directory of your project.
Open a command prompt.
Change to the eclipse home directory and type "eclipse -clean"
e.g.
C:/eclipse>eclipse -clean
This will ask for the workspace selection. It will also force to set it as the default workspace.
Then, go to eclipsehome-->configuration-->settings folder.
open org.eclipse.ui.de.prefs in a notepad.
set this property to true from false.
SHOW_WORKSPACE_SELECTION_DIALOG=true
You will be asked for a workspace selection everytime.
If you want to change recent workspace manually in a configurationfile
org.eclipse.ui.ide.prefs exists in
eclipse > configuration > .settings > org.eclipse.ui.ide.prefs
open this file in an editor find RECENT_WORKSPACES in line #2 and in this line you can see recent workspaces and can change or even remove them.
In Eclipse, go to File -> Switch Workspace, choose or create a new workspace.
This is the only answer you got first when you search for default workspace, but any solution is not solved my problem, So I follow this step for a default workspace:
First copy shortcut icon for your eclipse.
Right click and go to properties,
add your workspace path with -data attribute,
In Target:
D:\eclipse_path\eclipse.exe -clean -data D:\workspace_path\workspace
For using the same shortcuts and preference into this workspace,
Export general --> preference from your working eclipse, it will generate one .epf file.
So, just import .epf file into your new workspace, and you are done.
If you want to create a new workspace - simply enter a new path in the textfield at the "select workspace" dialog. Eclipse will create a new workspace at that location and switch to it.
On Ubuntu I went to
~/.eclipse/org.eclipse.platform_4.3.0_1473617060_linux_gtk_x86_64/configuration/config.ini
and added this line at the bottom
osgi.instance.area.default=#user.home/workspace
and changed workspace to the dir path from my home to where I put my workspace.
I combined #Frank answer with #Ronan Quillevere's comment
My kepler eclipse went into not responding at boot (shortly after installing GAE support) which I traced to a corrupt workspace. I fixed this by closing kepler, renaming the workspace directory (in use) so kepler starts normally without a workspace, then used file >> switch workspace to generate new workspace. Then started populating that with my old projects that I still needed.
You can check the option that shows up when you start eclipse. Please see the figure below

Using ant in Netbeans problem

When I do: ant run from directory /home/me/workspace/OMI3/OperatorDisplays/
There is no problem.
In netbeans when I right click on build.xml in the same directory and select "run target", "run". Everything builds fine, but when running it seems that an evironment variable is not recognized.
Using System.getenv() I see that netbeans is running from /home/me, I want netbeans to run from /home/me/workspace/OMI3/OperatorDisplays
Thanks!
It seems you have to change the working directory for your project.
Go to the Properties screen of your project (File|Project properties (yourproject) menu or Properties in the project's contextual menu in the Projects tab).
Then in the Runcategory, you have a Working directory textfield. Put /home/me/workspace/OMI3/OperatorDisplays in it and it should work then.

Share / Export eclipse working sets

I have created a couple of java working sets for a project in my workspace and want to share them with other people (using different workspaces). Is there a way to export them?
You can try and export (as in "copy to another people workspace metadata directory"):
</path/to/.metadata>\.plugins\org.eclipse.ui.workbench\workingsets.xml
This is the file referencing your working sets.
z0r adds in the comments:
my team mate replaced his workingsets.xml with my version of the file, and it worked well.
However, you must exit Eclipse before replacing the file, because Eclipse will overwrite it with the old version when it exits.
I think you only need to do this once.
download the AnyEdit addon:
Description | Download page
and then use the following work through:
Via the menu bar: File > “Export…”
Select “General” / “Working Sets”
Click “Next >”
Select the working set(s) you want to export and where you want to export the file.
Click “Finish” to perform the export.
In Eclipse Indigo the working sets export has moved to Export -> Team Project Set and there is a check box top left to export working sets.
Although, File → Export → Team → Team Project Set is the correct way to export working sets, you could write an Eclipse External Tool.
External Tools
Open a new dialog by navigating:
Run → External Tools → External Tools Configurations…
Select Program and click the New button to create a new configuration.
Note: You will only need to use the "Main" tab.
Give the tool a title e.g. "Export Working Sets"
Windows
Location: ${env_var:SystemRoot}\System32\cmd.exe
Working Directory: ${env_var:USERPROFILE}\Documents
Arguments:
/c copy /y ${workspace_loc}\.metadata\.plugins\org.eclipse.ui.workbench\workingsets.xml workingsets-${current_date}.xml
Linux
Location: /bin/cp
Working Directory: ${env_var:HOME}/Documents
Arguments:
${workspace_loc}/.metadata/.plugins/org.eclipse.ui.workbench/workingsets.xml workingsets-${current_date}.xml