This page collects some personal notes on configuring and using the Eclipse IDE. I post them here mainly for my own benefit, since inevitably at some point I will forget an important detail that took me a long time to sort out the first time.
You are welcome to refer to these notes yourself… at your own risk of course. (If you notice any errors, please submit feedback using the home menu above or by posting a comment in the box below.) However, there are plenty of other webpages that provide more comprehensive coverage of similar material. Some of these are listed in the References section at the bottom of this page.
The Eclipse IDE is great, especially if you are learning a new language. However, in my opinion, Eclipse is very ugly right out of the box. Particularly annoying is the incredible waste of screen space, which is hard to accept if you ever program on a laptop. Fortunately, Eclipse is highly configurable.
- Go to Help–>Eclipse Marketplace and enter “Color Theme” in the find box.
- Install two plugins called “Eclipse Color Theme” and “Eclipse 4 Chrome Theme.” (If you don’t see them, it probably means they are not compatible with whichever version of Eclipse you have installed.)
- Once the themes are installed, go to Window–>Preferences–>General–>Appearance. Select Chrome Theme or Color Theme and set the options you like.
In particular, the Color Theme gives you options for darker color schemes like Zenburn, which might reduce eye strain. The Chrome Theme gives you options like “Sash Width,” allowing you to reduce the wasted space between workspace windows.
Tip: If you choose a dark color theme, like Zenburn, the colors may not work well with the default colors used for syntax highlighting by the IDE plugins, like PyDev. For example, PyDev uses a light yellow to show matched strings which (in Zenburn at least) makes all matched strings practically invisible. To fix this, use Window–>Preferences–>Editors–>Text Editors–>Annotations. In the Annotations box on the right select Occurrences and either disable matching or choose a darker color. (See screenshot below.)
In the example below, I’ve used the eye-dropper tool to make matched strings appear in the same color as the current line color.
(In the window on the left, the cursor is currently at the variable max_par, so PyDev hightlights all nearby occurrences of max_par. Before changing the default “Occurrences” color used by PyDev, it was impossible to read the highlighted strings.)
Once PyDev is installed, a Python interactive console (or REPL) can be configured as described on this page. Briefly, follow these steps
- From the Window menu, select Preferences–>PyDev–>Interactive Console.
- Check the box next to “Connect console to Variables Debug View?”
- Uncheck the box next to “Focus console when an evaluate command is sent from editor.”
- To use the console, select (highlight) a line of code in the Eclipse editor that you want to evaluate, then hit Ctrl+Alt+Enter. This brings up a window allowing you to choose which kind of interactive console you want.
This section lists the steps I took to setup a git repository in the Eclipse IDE and host it on GitHub.
The steps assume Eclipse is already installed. They are roughly the same as the steps given in the Egit github tutorial cited below in the References section, but in a different order.
GitHub is a web-based hosting service for software development projects that use git.
The combination of git and GitHub makes it very easy to maintain, share, and collaborate on computer files and software projects. But even if you don’t expect others to use the stuff you host on GitHub, keeping your files organized in the cloud is very useful if you’re not always working in the same location on the same computer.
GitHub is free for hosting publicly visible repositories. If you want private GitHub repositories, you must pay for the service. (Currently, this costs $7/month.)
Install Egit Eclipse plugin
- Help–>Install New Software
- From the “Work with” dropdown list select “–All Available Sites–“
- In the “Type filter text” box, enter Egit.
- Select “Eclipse Egit” (you don’t need the others).
- Click Next, accept the license, click Finish, then restart Eclipse.
Configure SSH keys
- In Eclipse, from the Window menu, select Preferences–>General–>Network Connections–>SSH2–>Key Management.
- Select “Generate DSA Key”, “Save private key”, and “OK” to save key without passphrase. Click OK to close the Preferences dialog.
- Login to your github.com account, then click the “Account Settings” icon in the top right of the github.com page.
- From the menu on the left of the Account Settings page, select SSH Keys. This should bring you to the page:
- Select “Add SSH key” and copy-and-paste the contents of the id_dsa.pub file generated in Step 2 above into the Key box. (You can see the contents of your id_dsa.pub file in a number of ways; e.g., open a terminal window and type `cat ~/.ssh/id_dsa.pub` or point a web browser to the address of the file, e.g., file:///home/yourusername/.ssh/id_dsa.pub.)
- After you have pasted your public key into the Key box on the github page, give the key a name in the Title box. Probably you only want to do this once for all the repos you connect to Eclipse, so you might pick a name like “Eclipse”.
Create git repo in Eclipse
- In the Eclipse Package Explorer pane, right click on your project and select Team–>Share Project.
- Select Git then click Next.
- Next to the Repository field, click Create and type the name of your project in the Name box. Select Finish.
- In the Eclipse Package Explorer pane, right click on your project and select Team–>Commit.
- Select only those program files that you want in the repository, type a commit message in the box, and click Commit.
Create and connect to a github remote repo
In this section, we will create a remote git repository at github.com and connect it to the repo we created in Eclipse in the last step. Follow these steps to do this:
- In the Eclipse Package Explorer pane, right click on your project and select Team–>Show in Repositories View.
- Under References, right click on Remotes and select Create Remote.
- The Remote name should be origin and the Configure Push radio button should be selected. Click OK. (Leave open the new dialog box that appears. We’ll come back to it in a moment.)
- Open a web browser, login to your github.com account, and create a new repository. (Do not select the option to automatically generate a README.md file.)
- When you create a new repo at github.com, and name it, say, myrepo, this produces a uri associated with the repo. If you select SSH as the transfer protocol the uri will be something like email@example.com:username/myrepo.git. Copy this uri with the copy button (or highlight–>right click–>Copy).
- Go back to Eclipse. In the “Configure push” dialog that we left open in Step 3 above, next to the URI box, click Change.
- In the Select a URI dialog, the URI box should have been set automatically to your github remote repository. In the Connection section of the Select a URI dialog, set the Protocol to SSH. (Leave Authentication as is, with User field git and Password field empty.)
- Select Finish–>Save (the button on the far left; i.e. do not select “Save and push”)
- Now, in the Git Repositories view, expand Remotes–>origin and you should see two ssh uri’s. The green (fetch) and the red (push). Right click on the red uri and select Push. The result should look something like this:
- Go back to your github.com page and check that the program files that you committed in the previous section have been pushed to the remote repository.
- Finally, make sure the git fetch function is configured properly. (The tutorial I followed implied that once you configured git push, Egit would automatically configure fetch, but for me this was not the case.) To configure fetch, go to the repositories view and expand Remotes–>origin. Right click on the green (fetch) arrow and select Configure Fetch from the popup menu. Change the settings so that the Configure Fetch box looks something like this:In particular, the Refs mappings box might be empty (as it was in my case), so you will have to add one. Click Add and in the Source box type refs/heads/*, click Next then click finish. It should look like this before clicking Finish:
If this does not result in a Configure Fetch dialog like the one above, you can click the Advanced button and edit the Fetch Ref Specs dialog box so that it looks like this:
Import, fetch, and pull code from github in Eclipse
If you already have other repos on github and you want to import these into Eclipse, or if you want to import the repo you created above into Eclipse on a different computer, Quinn Liu has a nice 6 minute tutorial explaining how to do this, and how to fetch and pull updates.
Some useful git commands
If you use Git through the Eclipse Egit plugin described above, the Team menu provides all of the Git functions you need. However, it is occasionally useful to do things from the command line. This section collects a few basic commands that are useful but easy to forget. (See also git — the simple guide.)
- List the currently set git parameters:
git config -l
- Stop github from asking for your username/password on every push:
git remote set-url origin firstname.lastname@example.org:username/reponame.git
Note: if this is a brand new repo, you must use:
git remote add origin email@example.com:username/reponame.git
See also: this post.
- List the currently set git parameters:
node.js REPL in Emacs
(This section obviously doesn’t belong on a page about Eclipse, but until I make a separate page about using Emacs as an IDE, I’ll keep miscellaneous notes about it here.)
- C-c C-j — send the current line in the current buffer to the command line in the *js* buffer
- C-c C-r — send the currently selected region to the command line in the *js* buffer
- C-c C-u — (assuming you have jshint installed) this checks the code in the current buffer for correctness