Eclipse 'loading descriptor' takes ages - java

We have a Java Spring MVC based project using Eclipse (Juno - the latest build), using the latest JVM 1.7 and Tomcat 7. Eclipse is pretty fast, and everything is set to default settings. Once it is all loaded up, it is lightning fast, which makes a pleasant change.
However, the only gripe is that if I open a project, it begins 'Loading descriptor', which as far as I can tell is our 185-line web.xml file. Sometimes this might take 5 minutes to load, sometimes might just not load at all. This prevents any changes being made, as the system waits for the descriptor to load before anything else happens. Pressing the stop button on this leaves the system 'waiting' for the cancel to go through, and the only way out seems to be to kill the java process is the task manager. If it does by chance load, then the system runs fine (unless you open another project for reference, then the fun begin again).
Is there some configuration that skips the descriptor (e.g. is it something to do with validation that can be skipped) or would there be some reason that the descriptor might not load properly?

This happens when your Project Explorer is open. Uncheck unnecessary options at Project Explorer's "Customize View" dialog. On the top right corner of the Project Explorer panel there is menu called "Customize View", go to the second tab called "Content" and uncheck unwanted options...

That problem occurred because "Project Explorer" performs loading of environment descriptor.
So after the eclipse was loaded, choose "Windows" -> "Open Perspective" -> "Java". It will open the "Package Explorer" instead of "Project Explorer".
You need to be quick and get it done before the eclipse load the descriptor.

As you mentioned you could try disabling all 'xml' based validations like so :
Start by disabling all XML / XSL based validation towards the bottom
in Windows -> Preferences -> Validation :
Type 'Validation' in Eclipse preferences and disable any XML related
validations, like so:
and,
Might be worth to try out the following:
Check your proxy settings. Are they such that if required your Eclipse would be able to connect to the internet ? The reason I ask is, with XML files Eclipse attempts to download the related schema files.
Also, check Eclipse' error log view to see whether there is something specific that it's trying to do when it hangs.
Do you have a source control plugin inside eclipse which is linked to the project containing the web.xml file ? If so, if you disconnect your network does it help ? Infact, I would recommend disconnecting your network connection and try opening the problematic project.
If this is an old workspace from a previous version of Eclipse, try importing this project into a new workspace ?
Hope the above helps.

Yes, the problem is in "Project Explorer". If you like to use the "Java EE" perspective (which by default opens "Project Explorer" view) then close the "Project Explorer" view and open the "Package Explorer" view.

Changed Explorer to Package Explorer
Window->Show View->Other->Java->Package Explorer
It works now.

In my case, renaming the web.xml to web-fail.xml stops the hanging.
At least, I replaced my 2.4 schema definition with the 3.1
`<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
`
and everything works fine again

My way to succes was deleting the project from the eclipse. And removing ".classpath",".settings" and ".project" files(".settings" is a directory). After that importing project into eclipse as existing maven project.

Related

Getting error message "Code Recommenders cannot download its model repository index"

My Eclipse works fine, but now, periodically a message box comes up saying
Code Recommenders cannot download its model repository index
What does this mean?
If you go to "Preferences"/"Code Recommenders"/"Models" you will see some Repository URL's listed. In my case it is http://download.eclipse.org/recommenders/models/photon/.
But when you call that URL you will get a 404 since the site has been archived in July 2019.
So this URL beeing invalid causes the Error. Since the URL is not available is seems save to silently ignore it, as beeing suggested in the error-dialog.
As beeing said in the Reviews on eclipse Marketplace the project is archived due to lack of comitting developers. And you may find an archived last version here: https://repo.eclipse.org/content/shadows/releases.unzip/org/eclipse/recommenders/stable/
As written in the other answer, Code Recommenders has been archived due to lack of active maintainers, see this forum post.
Therefore when the plugin tries to download the models it fails because the site does not exist anymore, and you will see the following error dialog:
While you could choose to ignore this download failure in the future, I am not sure if Code Recommenders actually does anything without its models (please correct me if I am wrong), so at this point you could also uninstall the plugin.
OR, you could download the models manually:
Download the archived data of Code Recommenders: https://archive.eclipse.org/archived_projects/recommenders.tgz (9.7 GB!)
Extract recommenders/downloads/models/photon
In Eclipse: Open "Window" > "Preferences" > "Code Recommenders" > "Models"
Remove the existing download.eclipse.org entry
Add a new entry with a file URI pointing to the folder you extracted earlier. Note that you have to percent escape the URI, e.g.
C:\Program Files\eclipse\recommenders becomes file:///C:/Program%20Files/eclipse/recommenders
Click the "Apply" (and Close) button
Note however, that since you downloaded the files locally and there is no active development, you won't get recommendations for new Java features.
I don't want any of you to have to download 10 gigabytes like in #Marcono1234's solution, so I re-uploaded version-specific code recommender models to mega.nz and shared them here.
Download the code recommenders
For Eclipse Juno users: https://mega.nz/file/tuRFGYQD#zB_mq6XwO7nupLqMDRWQRnnhD3-FAgT3ijtDQyGvjFE
For Eclipse Kelper users: https://mega.nz/file/NjxXFYyb#uwpP3zxESL02prgTimhDL35xPXMnDkbDwzrhJG1rcgc
For Eclipse Luna users: https://mega.nz/file/02g1DASB#3GSzaKtFSGsxhdnNx2aX47DoD22ZZ6aUu9eXTUvoxKg
For Eclipse Mars users:
https://mega.nz/file/xnQDTQLC#wmA0cfL_ChVHuQ9r0Mo_Js3ef_eDyg2yU6Z2_JTUPbE
For Eclipse Neon users: https://mega.nz/file/siBF1QYC#aVfX3-FS5sNfLmRqCPg6eUaovQPpEkMqIPWugv3E3qk
For Eclipse Oxygen users: https://mega.nz/file/9nAjUITQ#BpQ4HagdlrfZOelW8jqVgJWI-5QlA38JLCGpGoMbWpc
For Eclipse Photon users: https://mega.nz/file/oq5klCBR#vB8f0vmPH3gaYGwkw7U1SVThW5IxKMuvhBughN-sJi4
Extract it to any folders you want (in my case, c:\workspaces\eclipse\recommenders)
In Eclipse: Open "Window" > "Preferences" > "Code Recommenders" > "Models"
Remove the default entry
Add a file URL to the path you extracted your code recommender model. In my case, it's file://workspaces/eclipse/recommenders.
Click the "Apply" (and Close) button
Enjoy!

Eclipse-PMD Configure ruleset globally

So i am using the Plugin Eclipse-PMD (http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/) in a shared version control enviroment.
We have multiple smaller projects in the entire project.
Out of the box it seems that this plugin requires individual configuration for every single project.
The way it works it that it searched for a .pmd file in the project and read information from that.
But it's really inconvenient to do that for 10-20 subprojects.
There is a general setting under Preferences -> PMD. But this doesn't seem to apply globally, even if that global checkbox is checked.
What i basically want: I want to configure the plugin to respect a single ruleSet-file in one place.
There is another problem with configuring it subproject-specific: I cannot configure a relative path for the ruleSetFile in the .pmd-file.
The problem with absolute path is that the file is checked into version control ... so with every commit everyone else would have to readjust.
I found this commit: https://github.com/pmd/pmd/pull/36 but i cannot seem to make it work the way it's roughly described.
So, did anyone achieve what i am looking for?
Edit: Actually i cannot even specify any other file that is not ".ruleset" in the .pmd-file as <ruleSetFile> without specifying an absolute path??
The default value for ruleSetFile is ".ruleset". So i thought, analogous to that, i could create a file in the exact same dir, call it fooRules.xml, and specify it via <ruleSetFile>fooRules.xml</ruleSetFile> but it can only find it if put the entire path to fooRules.xml in there?!
Try eclipse-pmd (available in the Eclipse marketplace or via the update site http://www.acanda.ch/eclipse-pmd/release/latest). With eclipse-pmd you can configure your projects to use a single rule set file for several projects. It also stores its path relative to the workspace. You still have to configure each project individually though (for now, this will change in a future release).
To set up eclipse-pmd in the way you described you have to open the project properties of your first project, select the "PMD" property page and add the rule set. Select the rule set type "Workspace" and pick your rule set file.
For every other project you have to open the project's PMD property page where you'll find the previously selected rule set file which simply needs to be checked to activate.
If you set it up this way there will be a .eclipse-pmd file in each project containing the settings. If you check this into your version control system then no one else in your team has to set up anything (apart from installing eclipse-pmd).
Disclaimer: I wrote eclipse-pmd. Mostly because I had the exact same problems as you with the other plugin.
I've been struggling a long time to get this working with PMD for Eclipse. While Eclipse-PMD has this feature built-in, I had some other issues with it (e.g. I think it is not meant to create reports).
The trick was adding the rules to the project as a link.
Create the rule file, e.g. pmd.xml, in the parent folder of the project. Add the file to the projects to be checked, but add it as a reference. Therefore, drag the file from the explorer to the bundle and select:
In the project properties, in the PMD section, check Enable PMD and Apply and Close the settings.
Now close Eclipse. Edit the file with the name .pmd in the project folder by replacing the content with the following:
<?xml version="1.0" encoding="UTF-8"?>
<pmd>
<useProjectRuleSet>true</useProjectRuleSet>
<ruleSetFile>pmd.xml</ruleSetFile>
<includeDerivedFiles>false</includeDerivedFiles>
<violationsAsErrors>true</violationsAsErrors>
<fullBuildEnabled>true</fullBuildEnabled>
</pmd>
Restart Eclipse and right click the project. Select PMD/Check Code. Now, only the violations defined in pmd.xml should be reported.
Configuring PMD only using the GUI does not seem to work for me.

Netbeans - Error: Could not find or load main class

So I'm making a java application in Neatbeans 7.4, been working at it for a while, everything was fine, running the project worked fine, but now when I hit run project, I get the error
Error: Could not find or load main class phleveledit.MainWindow
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
I can't think of what I did right before this started happening, so I don't know what I should change.. The code doesn't appear to have any errors. Here's a screenshot of the IDE+project folder
Image (http://puu.sh/5ldYB) :
Any ideas?
Edit: Unfortunately I happened to fix this problem by removing some code, which probably had some errors Netbeans couldn't detect, but I don't know what was exactly wrong so can't vote on a correct answer.
Right click on your Project in the project explorer
Click on properties
Click on Run
Make sure your Main Class is the one you want to be the entry point. (Make sure to use the fully qualified name i.e. mypackage.MyClass)
Click OK.
Clean an build your project
Run Project :)
If you just want to run the file, right click on the class from the package explorer, and click Run File, or (Alt + R, F), or (Shift + F6)
Just close the Netbeans. Go to C:\Users\YOUR_PC_NAME\AppData\Local\Netbeans and delete the Cache folder. The open the Netbeans again and run the project.
It works like magic for me.
(AppData folder might be hidden probably, if so, you need to make it appear in Folder Options).
You can :
RightClick on project node and go to Set configuration
Select the main class for your application.
Then clean and build.
Even if the above steps don't work for you then then delete the Netbeans cache by deleting the (index) folder
User\.netbeans\SOME_NUMBER_reflecting_your_version\var\cache\index\
Sometimes due to out of memory space error, NetBeans does not load or find main class.
If you have tried setting the properties and still it is not working then try
Select the project from the project explorer
Click on Run in the Menu Bar
Click on Compile
It worked for me.
This condition happens to me every 6-months or so. I think it happens when closing NetBeans under very low memory conditions. I discovered that it could be easily corrected by (1) Rename your project, including its folder name using right-click on project explorer's project name---I put a simple suffix on the original name ("_damaged"). (2) Try BUILD. If that is successful, which it is for me, give three cheers. (3) Repeat step (1) to restore the original project name. BUILD and RUN should start without trouble.
I guess that the 'rename the project and folder' process causes a special rediscovery of the applications main location.
Try to rename the package name and the class/jframe names... The clean and build the application.
Right Click on the package name
Go to Refactor
Select Rename
Give it a meaningful name, preferably all in small letters
Click on Refactor
Do the same for the class/jframe names.
Last Select Run from Menu
7.Select Clean and build main project
That should do it!!! All best
I had the same issue once. The problem was not in the code. The cause was... renaming the project folder to some other non supporting name. My project name was "MobStick" and I renamed it to "MobStick - May 26, 2014 04:00PM". Renaming it back to normal solved my problem.
I have run into this error a couple of times as well and for me the above solutions did not work. What does seem to work is going to the Project Properties, and under Compiling toggling Compile on Save.
Using NetBeans 8.1, I got the dread
Error: Could not find or load main class
from carelessly leaving an empty line in the Project Properties > Run > VM Options field. Until you click in the field, you may not see the caret flashing out of place. Remove the empty line to restore equanimity.
I just ran into this problem. I was running my source from the command line and kept getting the same error. It turns out that I needed to remove the package name from my source code and then the command line compiler was happy.
The solutions above didn't work for me so maybe this will work for someone else with a similar problem.
I had the same problem, I had the package and class named the same. I renamed the class, then clean and build. Then I set the main class in the "run" under the properties of the project. I works now.
I found the following steps useful:
Right-click on the project in the left toolbar.
Hover over the 'Set Configuration' item.
Click on 'Customize...'
Click on 'Browse...' by the 'Main Class:' item.
Select the correct class.
Click 'Select Main Class'.
Click 'OK'.
My problem was that, apparently, my package name was being listed twice. Selecting the class using the dialog changed 'aclass.MainClass' to just 'MainClass'.
Hope this helps,
-HewwoCraziness
Edit: This is expanding on Mary Martinez's answer.
You can solve it in these steps
Right-click on the project in the left toolbar.
Click on properties.
Click on Run
Click the browse button on the right side.(select your main class)
Click ok
Possible Fixes:
Fix 1
Go to project properties (right click on the folder of your project in netbeans)
On left tab where it shows the categories, click on the "Run" selection
Then click on Browse to find the Main class you use on your project
Fix 2
Go to C:\Users\name\AppData\Local\Netbeans
delete the Cache folder.
Rebuild and Run
Fix 3
Download most recent version of Netbeans
Fix 4
Download most recent version of JDK and configure Netbeans to use that
I had the same problem for 3,4 days. On my PC my Jar file snapshot would give me this error while on my laptop it would work fine, I tried all the tricks shown above and on other forums like deleting cache, selecting main project file, etc, but somehow I was sure the reason it cannot find the main class when I would execute the JAR file was may be due to classpath issue in maven configuration, and I was right and I fixed it using following steps:
Right-click on the project, and go to the properties
Inside the properties go to Actions
On the right side in Actions select "Run Project" and you will see properties below
Inside "Set Properties" make sure exec.args=classpath %classpath "package_name"
In my case, the package name was accompanied by the main class. So my main class was Login while the package name was com.mycompany.islamic_center_app1, When I checked the entry was
com.mycompany.islamic_center_app1.Login
All I did was remove ".Login" from com.mycompany.islamic_center_app1 and it was fixed, no more errors.
close netbeans.
open netbeans again.
choose new project>>java application.
click next.
deselect create main class.
now make the application
clean build run
For more reference watch this video
try this it work out for me perfectly
go to project and right click on your java file at the right corner,
go to properties,
go to run,
go to browse, and then
select Main class.
now you can run your program again.
I had the same problem and I moved the project to a location where the path had no none-english letter and that fixed the problem
if you are on window os, then try to start NetBeans via administrative mode. right click on NetBeans icon and "Run as Administrative".
If none of the above works (Setting Main class, Clean and Build, deleting the cache) and you have a Maven project, try:
mvn clean install
on the command line.
Had the same problem here. Usually Clean and Build solves much of the problem. It happened to be caused by a wrongly installed plugin.
I faced the similar issue with Netbeans 10 and JDK 1.8.
I was not able to choose the right class to launch the project
When I compile or run the project, it shows me the Class name as "initializing view, please wait ...", I could not select the class name.
The issue was resolved with the NetBeans11.3, I am able to choose the correct Class file without any other changes, and the project is launched without any issues.
I had the same issue but none of this thread's solutions worked for me. Finally, it was OneDrive that caused the issue (for once more). So, I simply moved the NetBeansProjects folder from Documents which is synced with OneDrive, to C:\Users\yourName\AppData\Local\NetBeans (selected this path as there is already a NetBeans folder) and that was it, case closed.
If you also have NetBeansProjects to a OneDrive syncing folder it is worth trying this solution, just be sure that the path you will select is not synced with OneDrive. Also, remember to close Netbeans before making the folder change and after you move the folder to the new path you need just to open Netbeans again, go to file menu/open project and select your project from the new path.

Refactoring package name breaks entire app

I am trying to refactor my package using Eclipse
org.sheehan.activity
to
org.sheehan.stocks.activity
For some reason my project just blows up when I do this and R doesn't get regenerated. How can I refactor properly?
UPDATE:
I updated my Android Manifest to reflect the change. R still doesn't get regenerated. Even after a clean. The compiler is complaining about org.sheehan.activity.R
I resolved by:
Android Tools > Rename Package Application
If you renamed properly, all your references across your project should have gotten updated. After doing this, clean your project by going to Project > Clean. This should fix it.
Fixing missing reference to R in eclipse:
Refactor -> Rename`
Build -> Clean
Android Tools -> Fix Project Properties
select the base package of your project in the eclipse package explorer, press F2 (Rename), in the rename dialog: SELECT ALL the checkboxes.:
That should do it
The package name doesn't update in the XML files. Specifically your manifest which needs to know the base package.
For more advanced imports and refactors, literally closing the Eclipse IDE can refresh a cache that causes random errors like "End position lies outside document range" or the "what once worked now doesn't hair puller outter errors."
Signs you should close Eclipse when trying to rename things are:
When you import a project, do some refactoring (like trying to change the package name), then delete the project and try again, you will see immediate R.java errors when you didn't before
When you are importing projects that have manually generated R.java files that have custom imports like "com.ns.proj.R" and don't see the name update in Preview
The box that asks if you want to "Rename subpackages" is checked unexpectedly
the code in the "Preview>>" looks as if it's been complied before instead of black and white code with the proper names replaced
you get XML errors in the manifest activity name like this
android:name="com.ns.proj.CustomCocom.ns.proj.CustomControlse="#android:style/Theme.Light.NoTitleBar"
when it should be
android:name="com.ns.proj.CustomControls"
android:style="Theme.Light.NoTitleBar"
There are too many to name obviously, however this is as important as "keep your eye on the ball" in sports. Something that is so easy to forget, yet things like these apply to other software programs like Dreamweaver (e.g. when you use the Dreamweaver "Put" option instead of FTP dragging with FileZilla and you notice your domain isn't updating your changes online). I called Adobe when I first started as a developer 8 years ago because I knew I wasn't doing anything wrong. They said sometimes the generated files to perform the action get corrupted...in other words, IDE's have bugs too!
In general, close the IDE before you off yourself...it could save your life!
Right click in your Project, go to
Android Tools > Rename Package Application
Sometimes if Project > Clean doesn´t work, so Delete /gen and /bin folders of your project.

Eclipse/Java code completion not working

I've downloaded, unzipped and setup Eclipse 3.4.2 with some plugins (noteable, EPIC, Clearcase, QuantumDB, MisterQ).
Now I find when I'm editing Java projects the code completion is not working. If I type String. and press ctrl+space a popup shows "No Default Proposals" and the status bar at the bottom shows "No completions available".
Any ideas?
Try restoring the default options in 'Windows > Preferences > Java > Editor > Content Assist > Advanced'
An example of the kind of data you see in this preference screen, however not necessarily what you currently have.
(From Vadim in this blog post " Content Assist Duplicates in Eclipse (Mylyn)":
if have duplicate Mylyn entries, uncheck the duplicate entries that do not contain "(Mylyn)" in their name)
The Eclipse help page defines the default list to restore:
Select the proposal kinds contained in the 'default' content assist list:
Other Java Proposals,
SWT Template Proposals,
Template Proposals,
Type Proposals
I'm adding an answer here in case someone else finds this on Google. Same symptoms; different problem. For me, the type caches had become corrupt.
From http://mschrag.blogspot.co.nz/2009/01/open-type-cant-find-your-class.html
Quit Eclipse
Go to workspace/.metadata/.plugins/org.eclipse.jdt.core
Remove *.index and savedIndexNames.txt
Restart Eclipse and search Ctrl+T for the offending type. The indexes will be rebuilt.
In case someone comes here and want to activate the autocomplete function, go to
Preferences -> Java -> Editor -> Content Assist.
Then in the Auto Activation section fill in Auto activation triggers for Java:
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._
For those running Xfce + having IBus plugin activated, there might be keyboard shortcut conflict.
See more info on my blog: http://peter-butkovic.blogspot.de/2013/05/keyboard-shortcut-ctrlspace-caught-in.html
UPDATE:
as suggested by #nhahtdh's comment, adding the some more info to answer directly: IBus plugin in Xfce uses by default Ctrl+Space shortcut for keyboard layout switching. To change it, go to: Options and change it to whatever else you prefer.
Check the lib of your project. It may be that you have include two such jar files in which same class is available or say one class in code can be refrenced in two jar files. In such case also eclipse stops assisting code as it is totally confused.
Better way to check this is go to the file where assist is not working and comment all imports there, than add imports one by one and check at each import if code-assist is working or not.You can easily find the class with duplicate refrences.
Another solution which worked for me is to go to Java--> Appearence --> Type Filters and do disable all
None of these worked for me.
I was experiencing this issue in only once particular class. What finally worked for me was to delete the offending class and recreate it. Problem solved... mystery not so much!
If you have installed Google Toolbar for IE, may be you can face the same problem. Because, the toolbar capture the shortcut ctrl+Space.
I had this problem and like #Marc, only on a particular class. I discovered that I needed to designate Open With = Java Editor. As a Eclipse newbie I hadn't even realized that I was just using a plain text editor.
In the package explorer, right-click the file and chose "Open With".
I faced this problem, and spent hours trying to figure out the issue. tried to follow the steps mentioned in the different answers above, the solution I found is on the same lines as Mona suggested, but slightly different. Tried to add as a comment to Mona's answer but no option was available.
Issue with my eclipse was, classpath somehow got corrupted and all the jars and dependent projects were missing. after taking the latest .classpath from repository it worked fine.
Check that you did not filter out many options inside the Window > Preferences > Java > Appearance > Type Filters
Items in this list will not be appear in quick fix, be autocompleted, or appear in other various places like the Open Type dialog.
I also face this issue but it is resolved in different way.
Steps that I follow may be helpful for others.
Right click on project (the one you are working on)
Go to Properties > Java Build Path > JRE System Library
Click Edit... on the right
Choose the JRE 7
Once you have you configuration checked and completion is still not working:
make sure you have the right directory structure.
Do you see the right icon beside the file?:
It will tell you how the file will be treated by Eclipse:
I am posting this answer as I had that story with with Maven webapp artifact. By default Maven-WebApp does not create folder for sources and I put my Java into resources, wondering for 5 minutes what was going on... :)
Running STS on Java Spring Boot projects, here's what works for me :
Maybe this helps other people who come across the same issue.
My setup: old Gradle project (version Gradle 2.12) made by someone else, imported using the Gradle Import Wizard into STS (Eclipse Oxygen.2 (4.7.2)).
Code completion did not work either (and I still have hollow Js at the Java files), but at least I got the code completion to work by doing:
right click on the project folder > Properties > Gradle > Configure Workspace Settings > Java > Editor > Content Assist > Advanced
check "Java Proposals in upper window.
2x Apply & Close
I have run into this problem since upgrading to Eclipse 2019-09. Based on some of the suggestions above, this is what worked for me.
I had to go to Eclipse -> Preferences -> Java -> Editor -> Content Assist -> Advanced.
I found out that if I turn on any of the key binding proposals, Java Non-Type, Java, Java (Task-Focused) or Java Type proposal, then I was able to use auto complete. If I turned them all on, then not only did auto complete work, but I got duplicate methods listed. I am guessing, but I will probably used Java Type Proposals. Any clarification of what differs for these four types would be appreciated.
In my case, Intellisense had only disappeared in a few classes in one project. It turned out this was because of a missing library on the build path (although it worked previously).
So definitely check all the errors or problems in Eclipse and try to find if a library may be missing
For those who use the latest 3-19 eclipse build:
It just happened to me when upgrading from Oxygen to 3-19 eclipse version, so I assume the auto-complete feature does not migrated correctly during the upgrade process.
The only solution that worked for me was to create a new eclipse workspace, and import the project/s to it. It might take a few minutes, but it worth it - comparing to the time spent on other solutions...
I ran into this and it ended up being I was opening the file with the text editor and not the java editor.
For me the issue was a conflict between several versions of the same library. The Eclipse assist was using an older version than maven.
I had to go to the .m2 directory and delete the unwanted lib version + restart eclipse.
I experience problems on Eclipse Neon when editing a file which does not belong to the project directory. When I copy the same file to the project root directory, not even to the src directory, the completion starts working.
When the file is opened from a different directory, only completion for JRE works. That is for example: java. completes, but junit. does not.
Just in case anyone got to a desperate point where nothing works... It happened to us that the content assist somehow shrunk so no suggestion was shown, just the "Press Ctrl+Space for non-Java..." could be seen.
So, it was just a matter of dragging the corner of the content assist to enlarge the pop-up.
I know, embarrassing. Hope it helps.
Note: this was an Ubuntu server with Xfce4 using Eclipse Oxygen.
If you're experiencing this in an enum, or when initializing an array with anonymous classes, it's a known bug in Eclipse. See Eclipse content assist not working in enum constant parameter list.
We can change the settings as per our requirement.
Suppose we want to make java proposal as highest priority we need to do changes as shown below.
Windows > Preferences > Java > Editor > Content Assist > Advanced
Choose Java proposal and click on up button
For me in Sep 2021 it was an odd Eclipse bug. I had a multi-line string inside an annotation in my Class. This caused just that particular class to fail when trying to code complete (even though the class compiled just fine).

Categories