Set Up Eclipse
Objective: Set up Eclipse on Your Computer
Due: Friday before class
Eclipse
Eclipse is a commonly used Java IDE. It can greatly improve your productivity, especially as you learn to use it well. Eclipse is commonly used for enterprise development because many tools are built in. There are other IDEs. Learning one IDE will make learning other IDEs easier.
Installing Eclipse
If you're not using a lab machine, you'll need to install Eclipse.
You can install through the Eclipse installer (which could be helpful; first on the page) or just install Eclipse directly. There are multiple versions of Eclipse, but you should download the Eclipse IDE for Enterprise Java and Web Developers (the first under the IDE Packages) so that you have the same version that is on the lab machines.
Using Eclipse
Start Eclipse. If you're on a lab machine, run Eclipse on the command line by typing eclipse.
Once Eclipse opens, if necessary, skim through the Welcome window and then close it to get to the typical view of Eclipse.
Eclipse has a lot of different perspectives. The
Eclipse documentation says "Perspectives provide
combinations of views and editors that are suited to performing a
particular set of tasks. For example, you would normally open the
Debug perspective to debug a Java program."
Make sure that
you're in the "Java Perspective" by going
to Window --> Perspective --> Open Perspective
--> Java
Close the Task List
window in the right
pane. Tasks/Mylyn can be very helpful in reminding you about tasks
you need //TODO
and integrating with Issues
repositories, but we need to focus on other views for now.
If you have used Eclipse before or you want to put your code for
this course in a specific location, create a new workspace: go
to File --> Switch Workspace
,
choose Other
and then make a new workspace
directory (e.g., cs209_workspace
).
Java Project in Eclipse
- In the File menu, create a new Java project
using
File -> New -> Java Project
- Name the project
FirstProject
- Make sure the "execution environment JRE" is 21
(i.e.,
JavaSE-21
or similar). - Uncheck the box for
Create module-info.java file
(although it's fine if you do leave it checked; it's for a level or two above what we do
- Name the project
- You should now see a new Java project (a folder marked with a
J) in your Package Explorer view on the left-side of Eclipse,
with the name
FirstProject
- Expand the project to see its (limited) contents. You should
see the JRE System Library -- that's on the classpath. You should
also see the source folder named
src
Configuring Comment Generation
- Go to the "Preferences" menu. On a Mac, look under the "Eclipse" menu for "Settings". On Windows, click on the ‘Window’ menu bar option, then choose ‘Preferences’.
- In the filter bar, type (or start to type) Code
Templates. Click on
Code Templates
, click on the drop down forComments
in the center pane.Double-click on
Types
to edit the template (or click it and click the Edit button). Then, enter:/** * ${tags} * @author FILL_IN_YOUR_NAME */
Double-click on
Overriding methods
to edit the template. Then, enter:/** * ${tags} * ${see_to_overridden} */
This will give you a good starting point for generating Javadocs for overridden methods. (You'll see.)
Version Control in Eclipse
Configure Git in Eclipse
Eclipse has integrated Git through a project called EGit. Configure EGit to use your GitHub username and password.
- Go to the "Preferences" menu. On a Mac, look under the "Eclipse" menu for "Settings". On Windows, click on the ‘Window’ menu bar option, then choose ‘Preferences’.
- Type “git” in the filter bar, then choose the
path
Version Control (Team) > Git > Configuration
. - If the following entries don't already exist, click ‘Add
Entry...’. Enter
user.name
as the Key, and your name as the Value, then add another entry withuser.email
as the Key and your W&L email as the Value.
Using Git within Eclipse
Everything you did in git
on the command line, you
can do through Eclipse. Hopefully, you're proficient at git, so
learning the Eclipse GUI will be relatively easy.
There are two main ways to use Git within Eclipse: through
the Team
menu and through the Git Staging
view.
Open the Git Staging
view by going
to Window --> Show View --> Other --> Git
Staging
. You can move the view to whichever pane you like. I
tend to put this view in the right pane
with Outline
.
Open the Git Repositories
view by going
to Window --> Show View --> Other --> Git --> Git
Repositories
. You can move the view to whichever pane you
like. I tend to put the view in the bottom pane
with Problems
.
Open an existing (local) git repository
- In the
Git Repositories
view, click on the icon to "Add an existing local Git Repository to this view" - Click the
Browse
button and navigate to the top-level directory that has your git repositories. - Select one of your repositories in the search results and add it.
- In the Git Repositories view, expand the repository. You can explore the contents of the repository, although we haven't used some of these terms.
- Expand
Working Tree
. This is the "current" version of the code. Right-click on Working Tree and select "Import Project". In the dialog box, click "Finish". - You should now see a new project in your Package Explorer view on the left side of Eclipse.
- Make changes to a file and see how the Git Staging area is changing. You can commit the changes to practice, but don't push them!
Eclipse Tricks
- After you have written a method, type /** before the
method, and then hit
enter
and the Javadocs comment template will be automatically generated for you. - Use
command-spacebar
for possible completions. - Use
command-shift-F
to format code to be indented appropriately.