• No results found

Launching and debugging a program on a remote computer

In document Building Applications with JBuilder (Page 190-194)

two computers do not need to match. Note that when you install JBuilder, JDK 1.4 is automatically installed in the <jbuilder>/jdk1.4 directory.

You can also debug local code that is running in a separate process on the same computer JBuilder is installed on. To do this, start the process in debug mode and attach JBuilder to it. For more information, see

“Debugging local code running in a separate process” on page 9-9.

Additionally, you can set cross-process breakpoints, which is ideal for debugging client/server applications. For more information, see

“Debugging with cross-process breakpoints” on page 9-10.

For any type of remote debugging, you need to debug through a debug configuration. For more information on run and debug configurations, see

“Setting runtime configurations” on page 7-6 and “Setting debug configuration options” on page 8-68.

Launching and debugging a program on a remote computer

This section explains how to launch a program on a remote computer and debug it using JBuilder on the client computer. Briefly, you

1 Install the Debug Server on the remote computer and run it.

2 Either compile the application on the remote computer or copy the application’s .class files to the remote computer.

3 Use JBuilder on the client computer to launch and debug the application on the remote computer.

Important The source files for the application you are debugging must be available on the client computer. The compiled .class files must be available on the remote computer. They must match. Otherwise, unpredictable results may occur, including incorrect errors being generated or the debugger stopping on the wrong source code line. Every time you modify the source code, be sure to update .class files on the remote computer.

First, install and run the Debug Server on the remote computer. If JBuilder is already installed on the remote computer, you can start with Step 4 below.

1 Copy the debugserver.jar file (located in the <jbuilder>/remote directory) to the remote computer. Note the directory location you copy it to as it will be needed in later steps.

2 Copy the Debug Server shell script, DebugServer (Unix), or batch file, DebugServer.bat (Windows), to the same directory on the remote computer.

3 Make sure that JDK 1.2.2 or higher is installed on the remote computer.

L a u n c h i n g a n d d e b u g g i n g a p r o g r a m o n a r e m o t e c o m p u t e r

4 Go to the directory on the remote computer where the Debug Server files are installed. Run DebugServer to customize environment variables for the remote Debug Server.

For Unix systems, use the following command:

./DebugServer <debugserver.jar_dir> <jdk_home_dir> [-port portnumber]

[-timeout milliseconds]

For Windows systems, use:

DebugServer <debugserver.jar_dir> <jdk_home_dir> [-port portnumber]

[-timeout milliseconds]

where:

• debugserver.jar_dir - The directory on the remote computer where the Debug Server JAR file is located. On Windows systems, the drive letter is required.

• jdk_home_dir - The home directory on the remote computer of the JDK installation. On Windows systems, the drive letter is required.

• -port - Optional parameter that launches the debug server on a port different from the default, 18699. Change this value only if the default value is in use. Valid values are from 1025 to 65535. This value must match the value entered into the Port Number field on the Debug page of the Runtime Configuration Properties dialog box (on the client computer). See Step 6 below.

• -timeout - Optional parameter that sets the number of milliseconds to try to connect the remote computer to the client computer. When this number is reached, the process will stop. The default setting is 60,000 milliseconds.

An example of this command in a Windows environment is:

DebugServer d:\remote d:\jdk1.3 -port 1234 -timeout 20000 5 Press Enter to start the Debug Server.

When the Debug Server is loaded, JBuilder remote debugging functionality in launch mode is enabled. Once the Debug Server is running, you need to compile the application and copy the .class files to the remote computer. (You can also compile the application remotely.) Then, you use JBuilder, running on the client computer, to launch and debug the program on the remote computer.

1 Compile the application. You can compile the application using JBuilder on the client computer, then copy or use File Transfer Protocol (FTP) to put .class files on the remote computer. You can also compile the application directly on the remote computer using the -g option when calling the javac compiler. (This tells the compiler to add debug information to the compiled file.)

9-4 B u i l d i n g A p p l i c a t i o n s w i t h J B u i l d e r

L a u n c h i n g a n d d e b u g g i n g a p r o g r a m o n a r e m o t e c o m p u t e r

3 Open the project for the application to debug.

4 Create a debug configuration (it can be part of an existing runtime configuration or a new configuration):

a Choose Run|Configurations. To create a new configuration, click the New button. To edit a configuration, choose it and click Edit.

b For a new configuration, enter a name in the Configuration Name field.

c Set the Build Target to None.

d Select the Debug tab.

5 Select the Enable Remote Debugging check box. Select the Launch option.

6 Fill in the following fields:

• Host Name - The name of the remote computer. localhost is the default value. You may need to check the network settings on the remote computer to find the host name.

• Port Number - The port number for the remote computer you are communicating with. Use the default port number, 18699. Change this value only if the default value is in use. Valid values are from

L a u n c h i n g a n d d e b u g g i n g a p r o g r a m o n a r e m o t e c o m p u t e r 1024 to 65535. This value must match the -port parameter used to launch the Debug Server on the remote computer. See Step 4 in the previous section.

• Remote Classpath - The classpath where the compiled .class files for the application that you are remotely debugging can be found. This field works like other classpath fields - if the classes are in a package, specify the root of the package and not the directory containing the classes. On Windows systems, specify the drive letter if other than C:. This remote classpath only applies to this debugging session.

• Remote Working Directory - The working directory on the remote computer. On Windows systems, specify the drive letter if other than C:. This remote working directory only applies to this debugging session.

Warning The working directory is not supported in JDK 1.2.2. If your remote computer is running JDK 1.2.2 and you enter a remote working directory, the debugger will display a warning in the Console output, input, and errors view.

• Transport - The transport type: Either dt_shmem (shared memory transport - not available on Unix systems) or dt_socket (socket transport). For more information on transport methods, see “JPDA:

Connection and Invocation Details - Transports” at http://

java.sun.com/products/jpda/doc/conninv.html#Transports.

7 Click OK two times to close the Runtime Configuration Properties and Project Properties dialog boxes.

8 Start the debugging session by choosing one of the following options:

Once you start the debugger, the application you want to debug (based on the Remote Classpath setting) is launched on the remote computer.

The debugger is displayed in JBuilder running on the client computer;

however, you are debugging the .class files running on the remote computer.

Note If the application is already running on the remote computer, the

Command Shortcut Description

Run|Debug Project

Shift + F9 Starts the program in the debugger using the default or selected configuration. Either runs the program to completion or suspends execution at the first line of code where user input is required, or at a breakpoint.

Run|Step Over F8 Suspends execution at the first line of executable code.

Run|Step Into F7 Suspends execution at the first line of executable code.

9-6 B u i l d i n g A p p l i c a t i o n s w i t h J B u i l d e r

In document Building Applications with JBuilder (Page 190-194)

Related documents