Import Java code examples into Eclipse using Git

From Knowledge Kitchen
Jump to navigation Jump to search


Overview

Readymade code examples in Java for this course are publicly available on GitHub, an online resource for sharing and collaborating on code. It is possible to manually download these examples and then manually import each into Eclipse. However there is an easier way using a code versioning and sharing tool called Git.

Note that if you are using the command line, there are separate instructions for downloading these Java examples from the command line.

Fork the examples

Follow these instructions to make a copy of the example Java programs:

fork
  1. With a web browser, go to the examples repository on GitHub - https://github.com/bloombar/java-examples.
  2. Click the button that says "fork" to make a copy of these examples into your own GitHub account.
  3. You will automatically be taken to a web page showing your copy of these examples

Download your copy of the examples

Once you have made a "fork" of the Java examples by following the instructions above, you will need the URL of your copy's git repository in order to complete the following steps. The URL of your copy should be:

https://github.com/your_github_handle/java-examples.git

Replace "your_github_handle" in the command above with your own GitHub username. This URL will be used in Step 4 below.

Importing into Eclipse

In sum, you will automatically download the examples from GitHub and automatically import them each into your Eclipse workspace. You do this by using Eclipse's Git integration.

Follow the steps outlined in the screenshots below.

Step 1 - Select File->Import...
Step 2 - Select Git->Projects from Git
Step 3 - Select Clone URI
Step 4 - Enter GitHub repository details
Step 5 - Select the master branch
Step 6 - Select a local directory where the examples will be saved
Step 7 - Select to import existing Eclipse projects
Step 8 - Select all projects

Continue to completion and the examples will then appear in the list of projects in your Eclipse workspace.


Downloading updates

The examples may be modified from time-to-time by the instructor. Whenever you'd like to make sure you have the latest version of the examples, use Git's pull feature to automatically download updates.

Do this by right-clicking or control-clicking on any file in one of the readymade examples in Eclipse. Then select the menu option outlined in the screenshot below:

Step 9 - Make a git pull request to fetch updates


What links here