петък, 15 май 2009 г.

Debug Java applets with Eclipse

Debugging applets by System.out.println("Blah14") is not the best practice in case we have IDE-s like Eclipse:)
As we know, with Eclipse we can debug remote applications like java apps deployed on some container or application server.
You can debug applets in same manner:

1. Enable remote debugging in the Java Plugin:

- Start/Settings/Control Panel/Java/Java Applet Runtime Settings/View

- Add the following to the "Java Runtime Parameters": -Djava.compiler=NONE -Xnoagent -Xdebug -Xrunjdwp:transport=dt_socket,address=,server=y,suspend=n

2. Close all Web browser Windows

3. Put breakpoints in your source code (you need to have an Eclipse project containing the applet source code)

4. In Eclipse create a remote debugging configuration:

- Run/Open Debug Dialog/Remote Java Application/New

- Assign host = localhost and port = 9000 //or other

5. Open the page that contains the applet.
6. Press the "Debug" button in Eclipse and be happy.

Useful resources: