Building and running the project

By default, Eclipse builds your project's code automatically after every saved modification. It uses a customized internal compiler with some interesting features, such as executing a class even when it contains errors and incremental compilation (which allows compiling just parts of the project). After the modifications have been recompiled, it can highlight the problems with the code on the fly. You can see a list of these errors in the Problems view. If the view is not currently visible in the workspace, you can open it by navigating to Window | Show View | Problems.

However, if you are working on a project that's too big, or if you are using a machine with low resources, automatic building can slow things down. To disable it, click on Project and unmark the Build Automatically option. Once you do this, the project will only be built when you navigate to Project | Build Project or Project | Build All.

To run your project, select it in the Package Explorer view, and click on the green play button in the toolbar, or select Run from the Run tab. This will launch your project without any further configuration. If your project contains a class with a public static void main(String[] args) method, it will be executed. If more than one class contains it, you will be able to choose which one you wish to run. You can see the output of your program (if there is any) in the Console tab.

Creating a launch configuration

If your project needs customizations, such as arguments or a specific classpath configuration to run, you can create a launch configuration to meet these needs. For this, navigate to Run | Run Configurations. The following screenshot shows the launch configuration window:

Creating a launch configuration

On the left-hand side of the Run Configurations window, you have a list of all the launch configuration categories. To create a new launch configuration for a Java project, double-click on the Java Application category. If you have already run your application once with the Run button, there will be a default configuration in this category.

By selecting the configuration, you will be presented with the tabs that contain the launch configurations. A brief description of what each tab contains is as follows:

  • Main: This is where you will choose the project and the main class. The Search button beside the Main class text field allows browsing through all the classes with a main method within the project.
  • Arguments: This tab lets you set arguments for both the main class itself and for the JVM.
  • JRE: This tab lets you choose the JRE that will be used to run the class.
  • Classpath: Edit this tab to create a launch configuration with a specific classpath configuration. Modifying this tab's configurations doesn't modify the project's classpath configuration.
  • Source: This tab lets you change the source lookup path. As in the Classpath tab, these configurations don't modify the project itself and are only valid for this launch configuration.
  • Environment: This tab allows you to define environment variables for this run configuration.
  • Common: This tab contains the general configuration of the launch. It allows you to choose to allocate a console for the launch and write the output to a file instead of the console. The Save as section refers to the launch configuration file.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset