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. 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. There are multiple versions of Eclipse, but you should download the Eclipse IDE for Enterprise Java and Web Developers (the second one on the list) 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, close the Welcome window to get to the typical view of Eclipse.
Make sure that you're in the "Java Perspective" by going
to Window --> Perspective --> Open Perspective
--> Java
If you have used Eclipse before, create a new workspace for this
course: 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 18
(i.e.,
JavaSE-18
or similar). - Uncheck the box for
Create module-info.java file
- 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
Configure Git in Eclipse
Go into Eclipse. Eclipse has a plugin for Git called EGit. Configure EGit to use your GitHub username and password.
- Go to the "Preferences" menu. On a Mac, look under the "Eclipse" menu. 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 GitHub username as the Value, then add another entry withuser.email
as the Key and your corresponding 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.
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.
This should get you ready for the next assignment. Feel free to play around (e.g., by following the next set of instructions).
Optional: 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 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 these terms explicitly.
- 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, 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