MDK Development Cycle | MDK Wizard Configuration | Import a .war file into a new project | Export a project into a .war file
This chapter describes how to debug a servlet and JSP with the Eclipse platform. To explain the necessary steps we use the first example from the "Getting Started" section EXAMPLE1.WAR.
Step 1: Start application in debug mode
When you do not want to deploy your application all over again, which is done with the "Automatic" option, you can start your application manually. Select the Eclipse commands Run > Debug ... and select the "Launch Configuration" of your application. Press the "Debug" button and your application is started.
To bring your application to life you have to activate a browser window, go to the MI Homepage and start your application. The application will stop whenever it hits a breakpoint.The "Manual" method allows you to change Java code "on the fly", without deployment.
Before you start your application manually, you must click on the "Stop Mobile Engine" button first. Otherwise you will receive an "binding error" message.
Step 1b : Open a debugging perspective in Eclipse (the debug perspective is
usually shown automatically when the application is started in debug mode.
If
you use Debug perspective in Eclipse the first time, use the commands Window
> Open Perspective > Other
> Debug to open the perspective
Step 2: Select a line in the source code where you want to set a breakpoint.
If
you don't see any source code at the moment, you must change your perspective
to Resource Perspective and choose a source file. Now, when you now go back
to the Debug Perspective, you will see the selected file.
To set the breakpoint, you can double-click on the left side of the source window or choose Run -> Add/Remove Breakpoint.
Step 3: Start your application in the browser. When the VM reaches the break point it will stop, and you can examine the values of variables.
To check a value, you can mark the variable (for example with a double click) press the right mouse button and select "Inspect" from the context menu. The variable is shown in the "Variables" view (top right of the debug perspective). The "Variables" view has tabs on the bottom of the window. When you select the "Variables" Tab you can double click the value of the variable. A input field is opened and you can change the value of the variable.
With Step over (brings you to the next statement) or Resume(brings you to the next breakpoint) your application continues. The buttons can be found in the title bar of the "Debug" window.
Debugging a JSP page is not so easy. The source code will be compiled at runtime in an optimized mode. So even are debugging your JSP page you are not able to access the values of the variables.
Here is a work around.
Step 1: Start your Application (Run > ...)
When your application is started the JSP compiler will interpret the JSP file and converts it into Java code. In the next step the is Java code will be compiled.
You find the Java code and the class file in tomcat at: C:\<ME_HOME>\work
Right now, if you only start the application, then you only have the Initial.jsp code. Do you have to run through the whole application to get all of the Java servlet code first. To do that
Step 2: Create a new Project
You have to build a new project including the source files.
Select the Eclipse command File -> New -> Project
Create a new Java Project
Enter the Project Name, for example JSPDebug
Deselect the Use default check box.
Enter the source path: C:\<ME_HOME>\work\Name_of_JSPapplication
Press Next > to continue with the wizard.
Accept the following dialog menu and create the project
Eclipse tries to compile your project but will not succeed, because the required libraries are not included in the project. We have to include them now:
Open the projects properties
Select the Java Build Path settings.
Select the tab Libraries
Add external jars for MI - to shorten the procedure, all .jar files in the C:\<ME_HOME>\lib folder.
Step 3: Build your project.
The class file compiled by JSP compiler will now be replaced by the file built from your project.
Add your new project to the debug settings. Open the debug wizard, select your configuration. Now add your Project in the Source tab.
Step 4: Start your application in the browser.