Previous Page
Next Page

1.9. Running Applications

Any Java application with a main() method, including the .java file created in Section 1.4.4, Using the Java Class wizard on page 24 and enhanced in Section 1.7.2, Templates, on page 39, is marked with the runnable icon decoration (a small green triangle), indicating that it is runnable. This section shows the different ways to launch (run) a Java application.

1.9.1. Launching Java applications

The easiest way to run a Java application is to select the class and then select the Run As > Java Application command (Ctrl+Shift+X, J) from the Run menu or from the Run toolbar button (see Figure 1-62). This executes the main() method of the application and writes any output (in blue) and error text (in red) to the Console view (see Figure 1-63).

Figure 1-62. Run As > Java Application command.


Figure 1-63. Console view.


Once an application has been run, it can be run again by selecting it from the Run > Run History menu or from the Run toolbar button (see Figure 1-64). Clicking the Run toolbar button or pressing Ctrl+F11 relaunches the last application you ran.

Figure 1-64. Run history.


1.9.2. Launch configurations

Whenever you run an application for the first time using the Run As > Java Application command, a launch configuration is created. A launch configuration records the information needed to launch a specific Java application. In addition to specifying the name of the Java class, the launch configuration can also specify program and virtual machine (VM) arguments, the JRE and classpath to use, and even the default perspectives to use when running or debugging the application.

A launch configuration can be edited using the launch configuration (Run) dialog accessible from the Run > Run... command (see Figure 1-65). The Main tab specifies the project and class to be run; the Arguments tab records the program parameters (as space-separated strings) and VM arguments; the JRE tab specifies the JRE to use (it defaults to the JRE specified in your Java > Installed JREs preferences); the Classpath tab is used to override or augment the default classpath used to find the class files needed to run the application; the Source tab specifies the location of the source files used to display the source of an application while debugging; the Environment tab is used to set environment variables; and the Common tab records information about where the launch configuration is stored and where standard input and output should be directed.

Figure 1-65. Launch configuration (Run) dialog.


The Eclipse Application configuration is used specifically to test Eclipse plug-ins you are developing. It provides a mechanism for starting up another workbench with full control over which plug-ins are loaded, active, and debuggable. This is discussed in more detail in Chapter 2, A Simple Plug-in Example.

The Java Applet configuration type is very similar to the Java Application type, but it is specifically designed to be used with Java applets. In addition to the tabs available for Java applications, it adds a Parameters tab that specifies applet-specific information such as width, height, name, and applet parameters.

The JUnit configuration is used to run JUnit test cases. JUnit test cases are a special type of Java application, so many of the configuration options are the same as for Java applications and applets. It adds a Test tab for specifying settings unique to the test case that will be executed. JUnit is discussed in more detail in Section 1.11, Introduction to Testing, on page 61.

The JUnit Plug-in Test configuration is used to run JUnit tests associated with an Eclipse plug-in. It is similar to the Eclipse Application configuration with the addition of the Test tab used by the JUnit configuration.

The SWT Application configuration is similar to the Java Application configuration and is designed to provide the appropriate runtime environment to launch an SWT application.

Tip

Eclipse supports hot code replacement during debug operations when using JDK 1.4 or above to run an application. If JDK 1.4 isn't your default JRE, you can specify it as the one to use when running or debugging an application by selecting it from the drop-down list on the JRE tab of the launch configurations dialog. If it isn't in the list, you can add it via the New button.



Previous Page
Next Page