Why can't IntelliJ IDEA import local packages in Go project? - plugins

I'm using Idea plugin for Go to work with my project.
The structure of my project is the following:
controller, entity, model, repository etc - are local packages (where one can use another).
Unfortunately, Idea can't import one local package from another:
With remote packages everything is just fine.
My project settings:
What am I doing wrong?

In my case enabling Enable Go modules integration helped.

you need to follow the correct project structure - https://golang.org/doc/code.html
basically, an environment variable called GOPATH should be set to your workspace root, such as ~/dev/go
in $GOPATH/src all the source code lives, for example, when you get a remote package from github, like go get github.com/someone/somepackage, the source code will be downloaded to $GOPATH/src/github.com/someone/somepackage and the import path from within a .go file is `"github.com/someone/somepackage".
your own code should live under $GOPATH/src as well, let's say it's $GOPATH/src/me/myproject, then your import path for entity and model are "me/myproject/entity" and "me/myproject/model"

For any one facing this issue, just tick the "Index entire GOPATH" option in Preferences->Go->GOPATH

Once I updated Preferences -> Go -> GOPATH -> Module GOPATH to include the root directory of my project (i.e. the directory containing src, bin and pkg) the imports of sibling packages started working ok. The "Index entire GOPATH" option was on, but didn't seem to help.

Indexing the Preferences -> Go -> GOPATH worked for me.

Please use one of the latest releases from github releases page and these kind of issues should be fixed.
Thank you.

Related

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.

Eclipse confusing package to be a folder

I have read some questions on this around here but my tries at the answer have not yielded success. Here is the problem:
Package:com.me.a
Folder(under above package):b
Java class(under above folder):Myclass.java
The proper package structure is com.me.a.b, but eclipse thinks 'b' is a folder. When I right click on b and go to build-source, there is an option that says "use as source folder" which then does something totally unwanted - creates a separate folder with the entire package path as a source folder, and uses a default package:
Folder: com.me.a.b
Package: default package
MyClass.java
How do I solve this annoying issue?
PS: I am unable to use images which to give a better idea but being new here, there is a restriction.
You have project/com/me/a/b set as the source folder. Your build path looks something like this.
You need to set project as the source folder. Your build path will look something like this afterward.
this is very strange. packages are basically folders, so saying that you have package com.me.a with a folder in it named b is essentially the same as having package com.me.a.b.
Or there is something wrong with the Eclipse's workspace metadata for this particular project?
Try creating new project with such package and class in it see if it is any different?
The behavior you describe when choosing "b" as a source folder is expected: you are basically telling eclipse that this folder b is a source folder, a root folder for source java files. this is the default package, every sub-folder of this one is considered a different java package...
I just had this same problem with ONE folder between about 100 folders. The solution turned out to be righ click on the folder (in the package view), choose "Build Path", and then "Include" (Instead of 'use as a source foldre' as the OP did). After that the folder turned into a package.

Eclipse projects not showing up after placing project files in workspace/projects

I've searched for 2 days and can't find anything. I find things that are close, but not what I need.
I got a new computer recently and copied all of my projects over to my new computer.
I opened Eclipse and generated a workspace, which I then closed out of Eclipse and copied my projects into the workspace/projects folder.
I reopen Eclipse and my projects do not show up at all in the package explorer.
I know that I have the correct folders in the correct directory.
The closest thread I found to this is: Eclipse - Import an existing project?
but even that didn't help, my projects already meet that...
I have tried refreshing, reopening, fooling with working sets, etc...
Just because you have a project inside the workspace directory doesn't mean Eclipse opens it or even sees it automatically. You must use File - Import - General - Import existing project into workspace to have your project in Eclipse.
For Juno: (With Source in E:\workspace and destination in C:\workspace)
Copy project directory in its entirety to the workspace directory.
(e.g. Copy E:\workspace\HelloWorld C:\workspace\helloWorld)
Start Eclipse.
Perform: File --> Import
Select: General -- > "Existing Project into Workspace"
"Next >"
Check "Select root Directory"
Select with "Browse Button"
Select "C:\workspace"
A list of existing projects will appear. Just check the ones that are in Bold (To Be Imported) then press the "Finish" button.
Review the Package Explorer and your copied projects should now be there.
This problems comes while .metadata of current workspace has been corrupted due to shut down Eclipse Unexpectedly. So if you face this problem just do the following steps:
Create a new workspace.
Import your existing projects to your new workspace.
you made it!
I had the same problem over and over again the solution that a have found works for now
Close Eclipse.
go to workspace.metadata.plugins
remove org.eclipse.core.resources
Start Eclipse
Do File->Import
General->Existing Projects into Workspace and import all the project from the workspace
Netbeans allows you to do a simple filecopy.
As you know, Eclipse doesn't work like that. You must explicitly "import" files and projects.
If you do import, and if there are no problems, then they should show up.
I'd consider:
a) making a backup of your existing workspace
b) deleting and reinstalling Eclipse
c) Trying another "test import"
You put them in the workspace/projects folder. You should put them directly in the workspace folder and then do an Import Existing Projects into workspace.
in Eclips the Package Explorer
Right click on any viewable project and select Show in -> Project Explorer
Package Explorer -> Right click -> Show in ->Project Explorer
you should be able to see all the imported projects in your Eclipse workspace
Even I had also observed the similar problem. I had closed my eclipse project because of some reason and on restart some of my file added were not visible in explorer even though corresponding file were existing.
Following solution worked for me:
Select whole workspace (Ctrl+A) ==> Righ click and press Refresh.
Or you could try:
Go to File -> Switch Workspace
Select your workspace (if shown)
As I had imported my project from a "git clone", I had to select File->Import-> Git->Project from git -> Existing local repository
Here's a specific problem I ran into when downloading a project from the internet.
Make sure you unzip correctly if it's zipped, you can sometimes get an extra level.
Make sure you place the project in the project file, not directly in workspace.
See if .project and .classpath have been renamed to _project and _classpath. You can't rename them directly so open a text document called .classpath and paste _classpath 's contents in there, saving as all files, not a .txt. _classpath can be opened with notepad.
Import the project from the file workspace. It will look for a folder called projects, your's should be inside it.
Hope this helps :)
The following worked for me.
Create a new project in eclipse.
After creating a new project in
eclipse, right click and select import.
General Import > File System
Select all the folders under your project except the root one. Click
finish.
This would create the required meta data and other internal eclipse project file system which will display your project's files.
You can also import the project directly as a file system. Follow the above steps if you are unable to import it directly.
Hi i also come across same problem, i try many options ,but finally the most easy way is,click of down arrow present inside ProjectExplorer-> customize View->filter-> unchecked close project.
And will able to see all closed projects.
I have tried many of the option suggested but at last importing project in new workspace solved my problem.
I think there is some problem in metadata files in old workspace.
I just wish to add one important detail to the answers above. And it is that even if you import the projects from your chosen root directory they may not appear in bold so you won't be able to select them. The reason for this may be that the metadata of the projects is corrupted. If you do encounter this problem then the easiest and quickest way to fix it is to rid yourself of the workspace-folder and create a new one and copy+paste your projects (do it before you erase the old workspace) folders to this new workspace. Then, in your new worskapce, import the projects as the previous posts have explained.
Yeah.... i kinda see what you need. I just came across same problem.
Here is exactly what i did. Now, bear in mind, this some low level knowledge, since i'm just starting. I made my life complicated, so i needed solution. I kinda found it on my own, using different directions from above answers.
I switched from win 10 on HDD to linux on SSD, so i needed my few of .class and .java imported into new workspace.
First i made a mistake, not using export option on windows and i just simply copied all of files from src and bin folders on win 10 to src and bin folders on linux. Of course workspace did not see those files.
Solution was found in IMPORT tool (which i should have used right away).
I put all of files in src folder into zipp file, and moved this file to some arbitrary folder (Home folder in my case).
Go back to src folder and delete all of .java files (you won't be needing them anymore).
Then i opened my empty project and selected import from File menu in Eclipse.
In import window, under option General (first one) select Import Archive.
Now simply find your zip file, and Voila! All is where it should be.
Problem: After creating a PyDev Project, the project does not show up in "PyDev Package Explorer" ;(
Solution: This is what I do to see them all in "Project Explorer":
I am using Eclipse IDE 2019-12
click on "Resource" icon at the top right corner
Now you shall see all projects show up in "Project Explorer".
Tricky note: now if you click on "PyDev" icon, you will see less projects show up in "PyDev Package Explorer" Magic?
What I did wrong about it, I used "import" - > "Projects from Folder or Archive" because I thought it would be the same thing. You have to use "Existing Projects into Workspace". Maybe this helps someone.
I experienced the same issues and I just click on Window -> Show view -> then Project explorer.
Then I got my project that was inside my eclipse workspace.

Some projects cannot be imported because they already exist in the workspace error in Eclipse

I am trying to import a project that me and my co-worker have been working on.. and keep getting this error after I select-- "import" then "import existing project" then click archive file, and then I click next, and this error comes up:
Some projects cannot be imported because they already exist in the
workspace
Uncheck the "copy projects into workspace" checkbox, and then click "refresh" button, you will be able to import the project
go to .project file in your project and change the name of the project in name tag
It has just happened to me too. Finally I realized that the project was already open in my workspace but it was not visible because of the selected working set. You have just to deselect the active working set and all opened projects will become visible.
This usually happens when you change the project directory physically without first delete in Eclipse.
You can view and delete these hidden projects in the following view:
Window -> Show View -> Other -> General -> Navigator
Then simply just continue with the process of import existing project.
In my case, I copied one of the projects (say 'Project1') from the workspace and pasted it to the same workspace. After that I modified the name of the pasted project (say to 'Project2'). I could not see it in the repository.
The main reason was .project file from the new project still had:
<name>Project1</name> instead of <name>Project2</name>.
So, I did following things in order to get the issue fixed:
Cut and paste Project2 outside the workspace
Change .project file to have <name>Project2</name>
Try importing Project2 again.
It worked for me.
You may have a project with same name in your workspace. Try to refresh (file->refresh) your workspace after deleting the another one with same name.
A typical situation occurs when you want to re-import a deleted project.
Projects in the Eclipse workspace must be unique. Note though that the project name need not be the same as the directory/folder name of the project, so you can either delete any existing project with the same name or alternatively rename the existing projects.
You have one occult directory named ".metadata" in workspace directory. Close Eclipse, delete ".metadata" and open Eclipse. When eclipse ask you about workspace make sure that ".metadata" isn't in workspace directory and click "ok" button to select default workspace.
Maybe you get the same project name in your '.project' file,check it,if yes, rename another name.than import again
If you've arrived at this because you have cloned a git project into the existing workspace and now you want to promote that workspace to a full fledged project then you should use the 'Git Repositories' view -> select 'Working Directory' -> Import Projects -> Existing projects.
Check if you have configured Eclipse to show ALL the working set. I once encountered exactly the same problem and it turned out I accidentally imported the project into the Other Projects working set. And my Eclipse configuration didn't show that working set in the package explorer, which lead me to believe that the project was not imported yet.
Updated for #Mawg:
First, click the Select Working Set...:
Then, choose No Working Sets:
This will effectively disable the working set and show all projects.
Try to rename the value of <name> tag which inside ".project" file of your project.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Rename this value</name>
<comment></comment>
<projects>
This will work for sure. Here you are just renaming your project.
EASIEST WAY: Right click on the project (folder that reads "MainActivity") go to Refactor -> Rename and you will get a text field allowing you to rename your project.
If you get an alert saying your project is out of sync with the filesystem press F5 (refresh) and try again.
Take a look in your workspace folder, you may have an old project there with the same name as the one you are importing (even though it's not being shown on eclipse).
When you delete a project on Eclipse, if you don't check the checkbox on the dialog, it just removes it from the view and doesn't delete the folder on the workspace directory.
In my case i had deleted the resources directory from my .metadata.plugins:
Go to your workspace
Enter .metadata.plugins
Delete : org.eclipse.core.resources directory
Another way I just found!
MOVE the project to some other folder and then import and if required copy to workspace
I had this issue when I deleted a project and tried to import the code again. Eclipse never really deleted the project and still held a reference to the project name/folder in the workspace. I had to created a new project with the same name and my code appeared as it was. I believe this only worked because the project path was never changed.
It was happened to me when
I delete project from eclipse Project Explorer and not checked the
remove content from disk.
Next time when I tried to import same project in workspace then got same problem.
To solve I just did FYI work that every kid can do :)
So How I solved it:
Cut Ctrl + x myProject folder from eclipse workspace to other location ie Desktop
Right Click Navigator (you can get it from Window > Show View > Navigator) and Refresh (it will prompt following dialog)
Just click Yes button and move your project folder back to eclipse workspace directory
Import again!
Now Rock 'n' Role
This warning means you just deleted project from navigator, but the project is present in the working set. Or else your working set has project with same name, so go to work-space directory and delete the project which has the same name and import again.
This worked for me.
File > New > Android Project > Create project from existing source
Location = the location of the project you want to import.
You will get a warning "An Eclipse project already exists in this directory.
Consider using File > Import > Existing Project instead." But you will be able to click "Next" and the project should in effect be imported.
In eclipse click file then select switch workspace then browse and select another folder. Now repeat the same process and this time there will be no error :)
I had a similar problem, I have the same repository I wanted to import twice. I renamed the existing project by right clicking on the project > refactor > rename then imported it again.
My problem was a little bit different.
For example, the project name (what I see) was FooProject and in the imported project, I was looking for the FooProject but I could not. However, Eclipse does not let me import that project because he claims that it is already imported. And then, I have looked at the .project file of the project and I have seen that the actual name of the project was not what I see (FooProject).
The conclusion;
The name of the project (what you see in Eclipse) may be different than the actual name of the project (what maven see). Because of this reason. Please be sure that they are the same name by checking .project file of the project.
Nothing about could not solve my situation. This is how I solved.
Close the IDE
Remove the same name project form workspace
Start the IDE
Clean all project (not sure this helped)
File > Import > Existing Project
click refresh button
import project
Done..
At least on Eclipse Juno, you can toggle on Advanced. Then select [groupid].[artifactid] from the Name Template dropdown. That should make your project uniquely named. (If you keep multiple versions of a given artifact, you can select [groupid].[artifactid].[version] instead). Be sure to click the Refresh button so the changes are visible. Wash, rinse, repeat as needed.
delete it from eclipse......u might have closed the project in eclipse by "(Rightclick)-->close project".....so even if you delete this project from workspace folder....it stays there in eclipse IDE as closed project.....you should delete it from Eclipse IDE...!!!
I have a slightly different situation whereby my eclipse stops responding and I have had to kill the session. After restarting Juno, then the particular project I was working on disappeared although .project file exists. Trying to import back into Eclipse would yield the same "Some projects cannot be imported .." or "A project with this name already exists" if trying to create a new project.
In the end, since I was using Working Sets, I managed to find this file .metadata.plugins\org.eclipse.ui.workbench\workingsets.xml. Manually added the missing entry and restarted eclipse and voila, it came back.
I had the same error because there was one more project under svn in workspace but with another name. So I've removed it.
This is what i have noticed for the above issue :- If the checkout folder (folder where your pom project resides) is same as the eclipse workspace folder then i am getting this issue
SOLUTION
when i used a separate workspace folder for importing the project, eclipse did worked smoothly :)
In case you are using Maven, make sure that your artifactId in pom.xml does not have the same name as any existing project name in your Eclipse project explorer.

Most efficient way of setting up a project Pydev PYTHONPATH in Eclipse (Helios)?

I want to add all folders in my Pydev project to PYTHONPATH so that I can reap the benefits of easily seeing unused imports etc. To do this I seemingly have to add all folders manually including the subfolders, one by one. Is there any way to add them all at once (recursively) or am I doing this completely wrong?
Now I right click the project in the Navigator and select Preferences. From there I go to Pydev-PYTHONPATH and finally I can add the folders.
Ok, just to give a proper answer, you should just add the folder(s) that you want to be in the PYTHONPATH as your source folder(s).
So, if you have a structure such as
/myproject
/myproject/src
/myproject/package
/myproject/package/__init__.py
/myproject/package2
/myproject/package2/__init__.py
You'd only want to add /myproject/src as your PYTHONPATH.
If you really had multiple folders to add there, you could edit the .pydevproject file (which is at the root of your project) and add multiple folders there at once (although as noted, you should only have few folders there, so, this is generally not needed -- although sometimes you may want that if you're adding multiple libraries to a folder or something alike).
The PyDev FAQ explains this properly on the items listed below:
How do I import existing projects/sources into PyDev?
How do I import existing projects/sources for a Django project into PyDev?
Check this out, this worked for me.
if you get an error “unresolved import: pydevd” try saving the file ‘manage.py’ first. the error should go away.
If the error persists: you need to make sure pydev is in your PYTHONPATH.
a) Go to Eclipse>Preferences>PyDev>Python Interpreter:
b) Click New Folder> (mac)”/Applications/Eclipse/plugins/org.python.pydev_x.x.x.x/pysrc”
c) Click “Apply” This adds the folder that contains pydevd.py to your PYTHONPATH. Eclipse automatically adds that to your project’s Python Library. This should resolve the problem and you can run it now.
https://djangounchain.files.wordpress.com/2012/12/screen-shot-2013-01-06-at-3-49-02-pm.png
(This should be a Comment to Fabio's answer, but insufficient rep)
(PyDev 2.7.1.2012100913)
Adding folders to the PythonPath does not work for EFS/Remote folders (rse://...)
When you click 'Apply' gives:
An internal error occurred during: "Python Nature: rebuilding modules".
java.lang.NullPointerException