2007年8月1日星期三

JPDA(Java Platform Debugger Architecture)

How let your changed java code updated to server? It is a big problem in develpping any non-trivial JEE project.

Resently, I run a JBoss 4.04 outside of Eclipse. The application archive(EAR) is so big that we can not run it in IDE environment. Then the debug process is boring. After having modify the java code, I have to package it, copy to deploy directory and restart the server. Ant can help me a lot but a debug round still takes me much of time.

In this situation, JPDA will useful. With the help of eclipse, I can use it to connect to a "Remote Java Application". You can find it in "Debug" dialog. Then you can inspect value of a varible and even modify the java code. Before that, you have to add a breakpoint to your java code. Only java with breakpoint can be modified and replaced to the server. This is a nice feature when you need modify code many times. When eclipse has attached remote server, any modified java code could be updated to the server. This is so-called "Hotswap Bug Fixing". Of course the source code should be added to the debug instance's "Source lookup path". Otherwise the server didn't suspend at your breakpoint. And you should mind that the compiled classes were swapped just in the server's memory and didn't updated to the server's file system. So after finished debug, you should copy the classes to the server's deploy directory.

Some other approaches I often used include Hot deploy and restart application (not server).

Hot deploy is used to deploy a archive such as .war or .jar(EJB) automatically when you put them in deploy directory. Most servers has this feature.

Restart application or Reload Context is used to reload all resource(classes and configuration) in one application eg EJB, or War. This approach is heavier than others. Tomcat will throw exception "Out of memory" after reloaded a web application many times.

To Netbeans, It provides debug mode also. There are some differences on "hot class replace" between it and eclipse.

Above is netbeans 6M10 debug tool bar. It has a "Apply Code Changes" button to submit the changed code to server. It need you do manually. This way is different from eclipse which done automatically.

没有评论: