Introduction to Eclipse

Open Eclipse

Open the eclipse program. It will prompt you to select a workspace. This is the directory which it will use to store your projects. In the lab, choose your flash drive. On your own computer, choose the directory you want to use. You can click on the "Use this as the default..." checkbox to always use this directory. If you don't click that checkbox then it will ask you to select a workspace each time you run eclipse.

When you open eclipse you may see the Welcome screen. Click on the close button on the tab to close the Welcome screen. You can open it again at any time by clicking on Help -> Welcome.

Create a Project

A project contains all the source code and any other files (such as data files) used to create a program. To create a project, go to the File menu and choose New -> Project -> Java Project. Enter a project name and uncheck the option near the bottom "Create module-info.java file". Click the Finish button.

Create a Class

To create a new class, go to the File menu and choose New -> Class or right click on the project in the Package Explorer and go to the File menu and choose New -> Class. If your class will contain a main method, select the checkbox to create a stub for main. An edit window will open for your class; use this window to enter your code.

Eclipse checks your code as you are typing it. If you have an error, you will see a red X to the left of a statement. Move your cursor over the X to see the error message. If you have a warning, you will see a gold triangle with an exclamation point to the left of a statement. If the triangle also has a lightbulb, you can click on it to see a list of changes you might want to make to resolve the potential problem. Sometimes eclipse will indicate a problem when you are in the middle of entering a statement; complete the statement and then see if the error is still there.

Add Existing Files to Your Project

Place the files into a directory outside your eclipse workspace. Open Windows Explorer and navigate to the directory which contains the files. In eclipse, open the project folder so the src folder is displayed in the Package Explorer window on the left. Drag the files from Windows Explorer to the src folder. You are prompted whether to copy the file to the project folder or link to the existing file. The advantages to copying are that you have all project source in the same directory, and you can create a different version of these classes. The advantage to linking is that you can have one version of these classes that is shared by all of your projects.

Where to Put Input Files

If your project reads from a file, put that file in the project directory. This is the parent of the src directory. Do not put the input files into the src directory, which holds your code. Put it in the top level directory for the project.

Execute Your Program

Click on the run button on the toolbar. The run button looks like the play button on any electronic device. The first time you run your program eclipse may ask whether you want to run it as an application or as an applet. Choose application if you are asked. All console output will appear in the console view at the bottom of the eclipse window. If the program takes console input, you will type your input in this same window.

Export an Existing Project

You don't have to actually export a project. Just copy the project directory to a new location, such as your flash drive or cloud storage. Be sure to copy the whole project directory, not just the src directory.

Import an Existing Project

If you have a project on your flash drive or on cloud storage, you need to import it into eclipse before you can work on it. You need to have the entire project directory, which is the parent of the src directory. If the project is on the cloud, download it to the computer you are using. Then click on File->Import. Select General->Existing Project into Workspace and click Next. Choose Select Root Directory and browse to locate the project directory. This brings up a window with the project; make sure it is selected, and click Finish. The project is still in the original location on disk and any changes you make will be made in that location.



Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2022