Eclipse Open declaration in Java project
Asked Answered
A

15

64

In an Eclipse SVN project I have a problem; when I tried to open a declaration of one class, I got this error:

Problems opening an editor Reason : projectname does not exist.

Also refactoring does not work.

I have searched the web and tried all found solutions but nothing helped. I have downloaded different Eclipse and Java versions and switched to a clean workspace but I still have the problem.

How can I solve my problem or which solution can I try?

Admix answered 8/1, 2013 at 1:45 Comment(5)
Did you try creating a new project and copying/moving code from the old one?Hockey
Did you delete your .metadata folder?Bosley
yes but both does not solve the problem :( or have my team somewhere delete any configuration ? under buildpath i can't do any action and this problem haven't a main classAdmix
I faced the same problem. Here is the question with the solutionNames
Did you solve this? I just installed Eclipse Luna on Debian 8 and I have the same error trying to open a method declaration.Slumberous
Z
41

Right Click on the project -> Properties -> Project Facets -> Click on the Configuration Link -> Click on Apply Button -> Click on OK button.

The above steps should set your project as a Java project.

Zendavesta answered 30/10, 2014 at 19:17 Comment(6)
Some project does not have facets already configured, could you suggest something else?Fairing
FYI The steps above ^ are to configure project facets.Zendavesta
Yes sorry, i'm just saying i don't have the configuration link.Fairing
Strongly recommended to backup your .project file which resides in your project folder before making this change.Hygroscopic
@Hygroscopic wish I would have read that comment sooner, I just exploded my projectRosol
This makes the classes lost.., I've no ideas how to get them backsRiccardo
V
25

If the project is a multi-module Maven project, then you need to import the child/module projects in addition to the parent/pom project. Then ensure that you only open source files via the child project. Java files opened this way will have the Refactor right-click menu item, and F3 Open Declaration etc. work properly. However if the Java file is opened from the parent project, these Eclipse functions will be missing.

It's quite frustrating when opening a file via a Search result, as the file will be found and listed in both the parent and child project. You need to ensure you only work with the file accessed via the child project.

I can't explain precisely what's going on with Eclipse, but it appears that Eclipse does not recognize the parent project as being Java projects, although it will correctly syntax-highlight the Java files whether they are accessed via the parent or child project.

Vetchling answered 2/4, 2015 at 21:1 Comment(5)
agree with you, I've experienced the same problem and is quite frusttrating to work with parent folders.. have you found any work around?Appendicular
"Then ensure that you only open source files via the child project." Thanks.. Came back from vacation and I had the error described by OP. Turned out I had the incorrect file open in Eclipse.. My brain still need some restarting after the vacation it seems.. ;)Sparrow
Still happening in 2018 - I've moved all 'pom-only' module placeholder projects into a separate working-set to try & avoid thisAllyl
This problem has been plaguing me for ages. Usually, I'd try one, and if it didn't work, I'd try the other (after search). But this time, I had to close and re-open eclipse to get the child recognized as a project.Bayadere
You can turn on the "Hide folders of physically nested modules (experimental)" feature which hides the parent folders. It is currently under Window -> Preferences -> Maven -> "Hide folders of physically nested modules (experimental)"Gurtner
D
6

You needed to to check it out as a Java Project, or preferably, its creator should have committed the .project and .classpath files for it.

Destination answered 8/1, 2013 at 22:17 Comment(2)
I'm having this problem and would like Eclipse to generate those for me based on my POMInstallment
You're not the OP, but ok. For that one you clone the repository and then use the (I think) Import as Maven project wizard (instead of going through the Git Repositories view as usual).Destination
E
3

I had this problem, too. It looks like after a search-in-workspace Eclipse opened a wrong file.

I pressed Ctrl + Shift + H (Open Type in Hierarchy), typed in the class name, and opened it. The file opened in a new tab, and everything was navigable again.

The difference in icons is:

the non-navigable J is in a contour font

Exponent answered 12/7, 2016 at 16:48 Comment(0)
K
2

you can solve the problem by create a new java project. when you check out the project,you should select the default option, [Check out as a project configured using the new project wizard].

Kries answered 2/7, 2013 at 9:42 Comment(0)
O
2

It might lack a builder. Check your PROJ_HOME/.project that should be like:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>the-one-user</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>

Ref: FAQ How do I add a builder to a given project?

Ovular answered 3/6, 2015 at 8:35 Comment(0)
M
2

Are you importing a maven project? If you importing a maven project, a file will be viewed in few perspective, especially if you open the file via "Open Resource (Ctrl + Shift + R)".

enter image description here

Let's look at the example above, "servlet-filter" (mark as 1) imported as maven project, and maven perspective project created in 2. If you open a file in 1, your "Open Declaration F3" will no work, because it is not a valid maven project. It will work if you open the same file in 2.

Hope this helps.

Mandiemandingo answered 10/9, 2018 at 7:22 Comment(3)
This is the answer I was looking for.Excerpta
This answer actually explains the reasons for @mrjmh's answer. Both answers merged would be perfect.Romberg
"If you open a file in 1, your "Open Declaration F3" will no work", can convert the "1" to faceted form, like @Zendavesta answer?Comportment
A
1

You need to import it as a Java/Maven project. Once you are done importing the project do the following steps

Go to Project -> Select Properties -> Select Project References -> Select/Check all the dependent/Child projects which you reference in the code base -> Apply and Close

Once you are done, try to clean the whole project. This should solve the issue.

Avunculate answered 4/2, 2019 at 6:46 Comment(0)
O
0

There is a bug in Eclipse (in Luna at least) for a very specific workflow, which might not be the answer to this specific question, but might be helpful for others.

If you perform an import into the src (meaning src folder has focus before performing import) folder from an extracted jar (as source code), and you place breakpoints in the nested *.java files in the nested packages, it won't hit those breakpoints. In order to get things to work, you must keep hitting F3 instead of using "Open Declaration" to get to the *.java file you want to set a breakpoint in, then add the breakpoint by double clicking in the far left margin. Then Run > Debug As > Java Application.

Or answered 22/9, 2014 at 22:59 Comment(0)
P
0

If the format of the project you checked out is of type Maven, you need to convert it to a Maven project first. It may be because the required classes haven't been generated yet. To do this, right-click on the project, click Configure, and then click Convert to Maven Project.

Protean answered 31/10, 2014 at 16:19 Comment(0)
S
0

I had the same in Eclipse Luna on Debian 8. I was missing the .classpath file when checking out from SVN. I manually copied it and changed some path names, refreshed the project and it was working again.

Slumberous answered 28/5, 2015 at 11:49 Comment(0)
T
0

It happens, when libraries are not available on class path of the project where F3 does not work. Select any other project and try to use f3 for navigation. It will work.

The solution is to add JAR files in your libraries or add libraries in your project. Try to use MAVEN project so that the problem can never occur.

Tyne answered 18/5, 2016 at 10:44 Comment(0)
P
0

I am using Eclipse Oxygen.2 (4.7.2). I don't see Project Facets after clicking project -> Properties. My solution is right click the project and click Configure, then select configure and detect nested projects, Eclipse will automatically generate the nested projects for you. May get some build errors in the new created projects, that should be easy to fix.

Pacifist answered 28/3, 2018 at 18:34 Comment(0)
S
0

Try adding Project Nature as 'Java'. Project ->Properties ->Project Naturesenter image description here

Sagunto answered 15/9, 2023 at 7:48 Comment(0)
G
-2

Go to Project properties,Select Project Facets then convert to project facets then click Ok then you will able to open editor.

Gatekeeper answered 24/2, 2016 at 15:15 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.