Eclipse 3.6 freezes at startup

My Eclipse 3.6 froze today at startup. I think what I did was that I clicked on the shortcut a bit too fast and two instances of Eclipse started running at the same time. I got an error message for one saying “workspace in use”. I killed the one that showed the error message but then my Eclipse will no longer start up.

I searched around for solutions.

The one that SORTA worked for me is below from here.

  • cd .metadata/.plugins
  • mv org.eclipse.core.resources org.eclipse.core.resources.bak
  • Start eclipse. (It should show an error message or an empty workspace because no project is found.)
  • Close all open editors tabs.
  • Exit eclipse.
  • rm -rf org.eclipse.core.resources (Delete the newly created directory.)
  • mv org.eclipse.core.resources.bak/ org.eclipse.core.resources (Restore the original directory.)
  • Start eclipse and start working. :-)

However, just doing that did not exactly solve my problem. I ended up going to the .metainfo/.plugins/org.eclipse.core.resources/.project directory and started deleting random project and trial on error. I finally found the project that was the culprit and fixed my issue.

Another suggestion by a coworker that has worked before if Eclipse freezes at startup is:

  • cd workspace\.metadata\.plugins\org.eclipse.ui.workbench
  • Make backup of workbench.xml
  • Edit workbench.xmlfile and remove all <editor> tags.

m2eclipse plugin jdk warning

More info – old issue but I ran into it on every freaking machine at home.

After I installed the m2eclipse plugin on Eclipse 3.6, I keep getting the following warning on the console:

The Maven Integration requires that Eclipse be running in a JDK, beacuase a number of Maven core plugins are using jars from the JDK.

Please make sure the -vm options in eclipse.ini is pointing to a JDK and verify that Installed JREs are also using JDK installs.

The solution that worked for me is changing the shortcut properties for eclipse e.g.

C:\JAVA\eclipse\eclipse.exe -vm "C:\Program Files\Java\jdk1.6.0_25\bin\javaw.exe"

I couldn’t get the eclipse.ini updates to work for some stupid reason.

Eclipse 3.6 Auto Static Import

After I started using JUnit 4, I really want Eclipse to automatically import org.junit.Assert.* statically for me. So when I do ctrl+space on methods like assertTrue, it will do:

import static org.junit.Assert.*;

for me.

I’ve figured it out for a while but I’ve been noticing it conflicting with my save action -> organize imports setting.

I finally got fed up and decided to investigate a bit further today.

Below are screenshots of Eclipse version 3.6.

  • Preferences -> Java -> Editor -> Content Assit -> Favorites all of the paths you wish to import statically e.g. org.junit.Assert.*
  • Then if you have Preferences -> Java -> Editor -> Save Actions -> Organize imports selected

    Make sure you update Preferences -> Java -> Code Style -> Orangize Imports to have Number of static imports needed for .* (e.g. ‘java.lang.Math.*) to 1.

    This way when you save your java files in Eclipse, it will not change your org.junit.Assert.* import to org.junit.Assert.assertTrue import. Otherwise it will require you to import again if you wish to use another method like assertFalse which in my opinion is annoying.

Eclipse: stop it from searching certain directories

It’s always annoying when you do a search (ctrl+h) in Eclipse and it produces results from directories you do not care about.

In my particular case, the project’s ant build expands the built war files into a directory named target. Since this directory duplicates the files in the regular WebContent directory, often times I end up editing the WRONG file from the search results. I will be spending minutes trying to figure out why weren’t my changes taken place once they are redeployed to tomcat.

So I was finally annoyed enough to do some research on how I can stop Eclipse from searching in directories I do not care about.

  1. Go to the navigator view of your workspace.
  2. Right click on the directory you do not wish Eclipse to search. Click on Properties.
  3. Select attribute Derived.

That should be all you need. Do another search to verify that the files in that directory no longer show up.

Eclipse 3.6 toggle comment findings

Despite of the usual convention of using ctrl+/, I found ctrl+shift+c is actually the way to go if you want it to work on everything.

I care mostly about being able to toggle comment in the following file types:

  • source code – comment with // or /* and */ block
  • markup e.g. xml/html – comment with <!– and –> block
  • property file value – comment with #

The following behaviors are tested in Eclipse version 3.6.

  • ctrl+/

    • source code: Toggles //
    • markup: No affect
    • property file value: Toggles #
  • ctrl+shift+/

    • source code: Only add but does not remove /* and */
    • markup: Only add but does not remove <!– and –>
    • property file value: No affect
  • ctrl+shift+c

    • source code: Toggles //
    • markup: Toggles <!– and –>
    • property file value: Toggles #

Eclipse CVS show history tags column stretched out

Gosh, I managed to double click on the show history tags column one time viewing a file that has gazillion tags. That stretched the tags column out of its capacity. There seems to be no way at least in UI to get that back to normal size so I can see the columns to the right of the tags column. I searched around and finally found a way to fix that without having to create a new workspace.

eclipes show history tags column stretched out

To Fix It:

starting from your workspaces folder, where “ProjectName” is the workspace you are having problems with.

\Workspaces\ProjectName\.metadata\.plugins\org.eclipse.team. cvs.ui\

open dialog_settings.xml

search for

"org.eclipse.team.internal.ccvs.ui.CVSHistoryTableProvider"

there is a tag in this section called “COL_TAGS.” That is the size of the tags column in the history view.

Eclipse run java code easily

Eclipse has a scrapbook function that allows you to run Java code on the fly. Sometimes you just want to test out a simple piece of code without having to create another Java class, execute it in the main method or create a junit to test it out.

For example, today I wanted to make sure I remember integer division in Java correctly. So I simply just want to execute the following piece of code.

int a = 10;
int b = 8;
int c = 17;
System.out.println(a / b);
System.out.println(c / b);

In order to do that, create a new Scrapbook page in your project.

  • Right click project -> New -> Other… (or CTRL+N)
  • Search “scrapbook”
  • Create a new scrapbook page. I just called mine blah.jpage.
  • Then paste the code in there. Highlight the code, right click and select execute or ctrl+U. The results of your execution will then show up in the console. That comes in pretty handy sometimes.

Eclipse Scrapbook