Eclipse FAQ

Frequently Asked Questions

This page provides a reference to the Eclipse compiler as covered in this course.
It is not meant to be a complete reference.
For that refer to the on-line documentation and to the Sun web site.

Click on one of the questions below to go to the ansewer.
Click on the Back button on the tool bar to return to the list of questions.

  1. How do I create a new project in Eclipse?
  2. How do I create a new package in an Eclipse project?
  3. How do I create a new class in an Eclipse project?
  4. How do I import a Java library class into an Eclipse project?
  5. How do I create a Run Configuration for a project?
  6. How do I create an executable JAR file?




How do I create a new project in Eclipse?

1. Select File->New->Java Project or File->New->Project as shown below. (Note: your version of Eclipse may or may not give you both options.)

2. If you selected File->New->Project then the dialog box shown below will appear. Select Java Project in the list then click the Next button.

3. In the dialog box shown below enter a name for the project in the text field. In this sample the project name is DemoProject. After entering a project name click the Finish button.


How do I create a new package in an Eclipse project?

1. Right click the src folder in the project and select New from the popup menu, then select Package from the sub-menu as in the image below.

2. In the dialog box that appears (see the image below) enter a name for the package. By tradition this name is prefixed with pkg but you can name it just about anything you want. After entering a name for the package click Finish.


How do I create a new class in an Eclipse project?

1. Right click the package in the project's src folder where you want to create the class. (Note: If you haven't added a package to the project then select the one called (default package). From the popup menu select New, then select Class from the sub-menu as in the image below.

2. In the dialog box that appears (see the image below) enter a name for the class then click Finish. Note: Make sure you enter the name in the text field labeled Name.


How do I import a Java library class into an Eclipse project?

The first time you use the name of a class from the Java Library in your program Eclipse will underline it in red to indicate that you need to add an import statement at the top of that source code file to add that class to your program. Fortunately Eclipse will add this import statement for you. Right select the class name. In the popup menu select Source and then in the sub-menu that appears select Add Import as shown in the first image below.

An alternate approach is to let the mouse cursor hover over the class name then in the popup box (shown in the second image below) select the import option.



How do I create a Run Configuration for a project?

A Run Configuration is used with a JAR file so that Java will know where the main() function is located.

To create a Run Configuration do the following:
1. Right click the project name in the Package Explorer pane.
2. From the Run menu select Run configuration...
3. Click the Browse button and select the Project.
4. Click the search button and select the file from the list that contains main()
5. Click Run.
The Run Configuration is now also available when you create a Runnable JAR file.





How do I create an executable JAR file?

An Executable JAR file is a compressed ZIP file with the .jar extension. It contains all of the .class files for a Java application and can be run just by double clicking the JAR file's desktop icon. Note, however, that any external files, such as directories of images used on buttons, must also be available to the JAR file as those files are not included in the JAR.

To create an executable JAR file do the following:
   
1. Right click the project name in the Package Explorer
pane and select Export from the popup menu. (Figure 1).

2. Select Runnable JAR File and click Next in the dialog box. Do NOT type anything in the "Select an Export Destination" text field.(Figure 2). If you do not see Runnable JAR File under Java in the list then click the + next to Java to expand that list node. When you are finished click the Next button.


Figure 1

Figure 2
3. Click the Browse button (Figure 3) and in the Save File dialog box that appears (Figure 4) select the project directory.
4. Enter an appropriate name for the JAR file in the File name text field. For programs to be turned in for CS 103 this name should be in the format ProgramName-YourName.jar. For example, in Figure 4 the file name that has been entered is JavaGUIDemo-rcoleman.jar
5. Click Save to dismiss the Save File dialog box.
6. From the Launch Configuration combobox (Figure 3) select the appropriate Run Configuration. This will probably be listed as something like
           New_configuration(1) - ProjectName (as in Figure 3) or
           ProjectName - MainClassFileName
7. Click the Finish button. Your JAR file will be created and saved to disk in the location you selected. Double click the JAR file to run the application.


Figure 3

Figure 4










This site is still under construction