| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> |
| <html> |
| <head> |
| <meta name="copyright" content="Copyright (c) IBM Corporation and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." > |
| <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> |
| <meta http-equiv="Content-Style-Type" content="text/css"> |
| <link rel="stylesheet" href="../book.css" charset="ISO-8859-1" type="text/css"> |
| <title> Running your programs </title> |
| </head> |
| <body> |
| <h1> Running your programs </h1> |
| <p> In this section, you will learn more about running Java programs in the workbench. |
| </p> |
| <ol> |
| <li> In the Package Explorer view, find <em>junit.textui.TestRunner.java</em> |
| and double-click it to open it in an editor. </li> |
| <li> In the Outline view, notice that the TestRunner class has an icon which |
| indicates that the class defines a <code>main</code> method. |
| <p> <img src="../images/org.eclipse.jdt.debug.ui/executable.png" alt="Outline view with selected TestRunner class"> |
| </p> |
| </li> |
| <li> Right click on TestRunner.java in the Package Explorer and select |
| <strong>Run As</strong> > <strong>Java Application</strong>. This will launch the |
| selected class as a local Java application. The <strong>Run As</strong> |
| context menu item is also available in other places, such as the Outline view. |
| <p> <img src="../images/org.eclipse.jdt.debug.ui/run_as.png" alt="Run context menu"> </p> |
| </li> |
| <li> Notice that the program has finished running and the following message appears in the |
| Console view telling you that the program needs an execution argument. |
| Running class from the Package Explorer as a Java Application uses the default settings for |
| launching the selected class and does not allow you to specify any |
| arguments. |
| <p> <img src="../images/org.eclipse.jdt.debug.ui/test_runner_console.png" alt="Console with error message: Usage: TestRunner [-wait] testCaseName, where name is the name of the TestCase class"> |
| </p> |
| </li> |
| <li> To specify arguments, use the drop-down <strong>Run</strong> menu in the |
| toolbar and select <strong>Run...</strong>. |
| <p> <img src="../images/org.eclipse.jdt.debug.ui/run_drop_down.png" alt="Run menu of the toolbar"> </p> |
| </li> |
| <li> This time, the Launch Configurations dialog opens with the TestRunner launch configuration selected. |
| A launch configuration allows you to configure how a program is launched, |
| including its arguments, classpath, and other options. (A default |
| launch configuration was created for you when you chose <strong>Run > |
| Java Application</strong>). |
| <p> <img src="../images/org.eclipse.jdt.debug.ui/run_dialog.png" alt="Launch configuration dialog showing the Main tab"> |
| </p> |
| </li> |
| <li> Select the Arguments tab and type <em>junit.samples.VectorTest</em> in |
| the Program arguments area. |
| <p> <img src="../images/org.eclipse.jdt.debug.ui/test_runner_args.png" alt="Arguments tab of the launch configuration dialog"> |
| </p> |
| </li> |
| <li> Click <strong>Run</strong>. This time the program runs correctly, indicating |
| the number of tests that were run. |
| <p> <img src="../images/org.eclipse.jdt.debug.ui/test_runner_output.png" alt="Console showing program output"> </p> |
| </li> |
| <li> <p>Switch to the Debug perspective. In the Debug view, notice that a process |
| for the last program launch was registered when the program was run.</p> |
| <p>By default, the Debug view automatically removes any terminated launches when |
| a new launch is created. This preference can be configured on the <strong>Launching</strong> |
| preference page located under the <strong>Run/Debug</strong> preference page.</p> |
| <p> <img src="../images/org.eclipse.jdt.debug.ui/test_runner_debug_view.png" alt="Debug view showing two terminated run launches"> |
| </p> |
| <em>Note: You can relaunch a terminated process by selecting <strong>Relaunch</strong> |
| from its context menu.</em> </li> |
| <li> Select the drop-down menu from the <strong>Run</strong> button in the workbench |
| toolbar. This list contains the previously launched programs. These programs |
| can be relaunched by selecting them in the history list. |
| <p> <img src="../images/org.eclipse.jdt.debug.ui/run_history.png" alt="Run drop down menu from the workbench toolbar"> |
| </p> |
| </li> |
| <li> From the context menu in the Debug view (or the equivalent toolbar button), |
| select <strong>Remove All Terminated</strong> to clear the view of terminated |
| launch processes. |
| <p> <img src="../images/org.eclipse.jdt.debug.ui/remove_all_terminated.png" alt="Debug view showing context menu"> |
| </p> |
| </li> |
| </ol> |
| |
| <p><img src="../images/ngrelt.png" border="0" alt="Related tasks"><br> |
| <a href="../tasks/tasks-9.htm">Changing debugger launch options</a><br> |
| <a href="../tasks/tasks-141.htm">Connecting to a remote VM with the Remote Java application launch configuration</a><br> |
| <a href="../tasks/tasks-142.htm">Disconnecting from a VM</a><br> |
| <a href="../tasks/tasks-130.htm">Launching a Java program</a><br> |
| <a href="../tasks/tasks-126.htm">Running and debugging</a><br> |
| </p> |
| |
| <p><img border="0" src="../images/ngrelr.png" alt="Related reference" ><br> |
| <a href="../reference/ref-51.htm">Debug view</a><br> |
| <a href="../reference/ref-4.htm">Run and debug actions</a><br> |
| </p> |
| |
| |
| </body> |
| </html> |
| |