I have been Eclipse for a while now. I did go through the initial “Eclipse or Netbeans” drama for a while and finally settled for Eclipse. For most practical purposes, they are similar, though each of them have their own advantages. So, it’s essentially a matter of preferance.
After many years of using it, I still discover things about Eclipse and it always surprises me that they would pack so much into the UI. I wish PowerBuilder does even 50% of that. (I don’t mean this to turn into a PowerBuilder rant session, but have you ever tried to cross reference what’s in System Tree and an object referenced in code?).
Pasting Java code into a Project Source directory
I often try simple programs to test out a Java function before I copy it to my application code. I even get code from the web and paste it into Eclipse, so I can test those samples in my workspace. To do this, I used to copy the code from the web, open a new Java class and paste the text into it. But, since my path may be different, I often end up in correcting the package name and/or Class file name. I kept doing it for a while, until I found out there is an easier way:
After I copy the code, instead of opening a Java class and pasting text into it, I can just paste to package and it automatically creates class and refactors package.
Copy the source text to clipboard. Right click and paste to the right source folder/package in your project. Here, I simply pasted to com.sam.test package. And it created the HelloWorld.java based on the class name. It automatically refactors it too!! It didn’t matter if the original class had any package at all or had a different package name. See the package name is now my package – com.sam.test.
Refactor a name, it automatically renames everywhere!
If you are like me, having worked on other tools before coming into Eclipse, you would have tried renaming a class using following ways:
You could have tried change the name of the class in the Text Editor. Eclipse will complain the containing Java file (compilation unit) has a different name. In my earlier days, I even saved it as a different name and deleted the old file. Or if you are used the resolving Errors in Eclipse, you would have hovered over errored text, which would have given suggestion to rename class or compilation unit.
After this, I would either global search to replace all the references to this class (which may cause more issues – supposed you renamed portion of a string?) or leave it to the compiler to report those.
I am guilty of all those approaches. Now?
I simply right click on the Java file/class in project explorer and say “Refactor”. It lets me type the new name, and it renames it everywhere!! I don’t need to search and replace.
Ant (build) Script
I admit. I use Ant. Not up with Maven yet. In the past, I used to create an Ant script manually. This was on top of setting up the Eclipse project. Sort of double work. Now??
I simply right click on the project, and choose Export. If I can’t find the right option, I simply type Ant into the search box and it brings up Ant Build file. I choose that and finish exporting. Voila! I have build.xml that I can edit.
And the reverse is always true. Suppose I want to set up my project on a team mate’s machine. All I need to give her is the Ant script. When she imports that, the entire project structure (including paths, libraries etc) are setup automatically into her Eclipse project.
Locating back an object in Project Explorer
Oh yeah, about my PowerBuilder question above, you can so do this in Eclipse. To be able to locate in the Project explorer, the Java file currently being edited in the Editor, You can right click, choose Show In -> Project Explorer, it expands the project and finds the class you are on!
I cannot even stop talking about finding referenced class files by highlighting the type and pressing F3 or by choosing “open type under cursor” options. I can keep ranting and raving about Eclipse all night long. I will keep that for future posts!
If you are reading this post and you have your own praise list for Eclipse, please post in comments. Thanks for reading!