Managing files and projects
Deleting a class
Now that you know how to create a project and a Java class, you might also want to know how to delete them. To remove a class file from a project, right click on it in the Package Explorer and select “Delete.” A dialog box asking you to confirm will appear. Selecting “Yes” will delete the Java file.
Deleting a project
To delete a project, right-click on the project in the Package Explorer. Again, select “Delete” from the context menu. To delete your project select the option “Also delete contents under…” and select “Yes.”
Before exporting a project, make sure you close any other projects
you don't want to export. This will make things a little bit simpler.
You can export a copy of your project as a zip file as follows:
Right-click on the project and select "Export...".
Expand the "General" option, select "Archive File", and
Select what you need to export (if the whole project just
check the project folder).
Select the "Browse..." button and locate the folder where you
want to place the zip file.
Enter a zip file name in "File name:" and select "Save".
Always verify the zip file created has the correct files.
You can go to a different workspace and import the zip file
to verify its contents.
You do not need to create any project before importing a project.
Just go to the "Java" Perspective, right-click on the Package
Explorer and select "Import...".
Expand the "General" option and select "Existing Projects into
Workspace". Do not select "Archive File" (yes, we know, is
Click on the "Select archive file:" option and using "Browse..."
select the zip file that has the project you want to import.
Renaming Java classes and files
To change the name of a project, class, file, variable or method: highlight the item, right-click, and select Refractor → Rename. You will then be prompted to enter a new name.
Searching a Java file
If you are editing a Java file and you want to locate a specific phrase somewhere in your code, you can use Eclipse’s search tool. Eclipse has a more advanced searching mechanism than most Windows applications. Select Search → Search. This will bring up the Search window, which has a series of tabs. These searching utilities makes it easy to quickly locate anything in your project, so experiment with the search tool—it can save you a lot of time later.
Things to keep in mind
- It is a problem if you ever get the popup message that automatic CVS operations are being disabled, particularly if you use more than one computer to work on projects from. That means that changes you make are only being stored locally, and not being sent to your CVS repository. If this happens, you should try restarting Eclipse. If that doesn’t solve the problem, you should come to office hours for help getting the problem resolved.
- If you use more than one computer to work on projects, you are strongly recommended to put your workspace on a USB key, and always use it with whatever computer you use (define that as the workspace when running Eclipse on any computer). If you do this, even if you do have CVS problems you are still using the same workspace with all computers at least.
Editing errors/warnings options
Here are some suggested settings for errors/warnings in Eclipse. You will find this section in Eclipse by accessing Window → Preferences → Java → Compiler → Errors/Warnings.
- Non-static access to static member → ERROR
- Method with a constructor name → ERROR
- Assignment has no effect → ERROR
- Possible accidental boolean assignment → ERROR
- Empty statement → ERROR
- Comparing identical values → ERROR
Adding 80-Characters Mark
You can follow the steps below to add a line indicating an 80-characters limit.
Notice the steps below do not work in a Linux environment. For such environment
you may want to try the following plugin:
Select "New.." and enter a name (e.g., CMSC), and select "OK"
Select "Line Wrapping"
In "Maximum line width:" enter 80 (for PC) and 88 (for Mac, as there seems
to be a bug that requires 88 instead of 80).
Select "OK" and "Apply and Close".
Select the checkbox "Show print margin". Notice that the number in
"Print margin column:" is not controlling where the line appears.
The previous number (entered in "Maximum line width") defines
where the line appears.
Select "Apply and Close".
Code Coverage for Eclipse
EclEmma is a free Java code coverage tool for Eclipse. For additional information
Notice that recent Eclipse versions already have code coverage features.