Using FastSwap to speed up development
By email@example.com on Oct 03, 2009
A fast turnaround time is something that most developers appreciate and since JDK 5 it is possible to redefine a class without dropping the class loader. However, the support provided by the JDK is limited and does not allow the developer to reshape the class, i.e., fields and methods cannot be changed/altered. FastSwap is a feature within WLS that, when enabled, is designed to overcome these limitations. For example, it will allow the developer to add new methods to an already loaded class and see those changes take effect immediately.
In order to take advantage of FastSwap, WLS must be running in development mode and FastSwap must have been turned on for that particular deployment. For applications deployed as an EAR, adding the
FastSwap will only monitor changes of classes in exploded directories so if an exploded EAR contains an archived WAR, any changes to that WAR will not be detected. Therefore, the WAR also needs to be unpacked and then FastSwap will monitor all the classes found under the web application's WEB-INF/classes directory. Note that any jars residing in WEB-INF/lib will not be monitored.
Developing with FastSwap
Once FastSwap has been enabled for a particular deployment, it will pick up any change made to a monitored class at runtime, allowing the change to take place immediately.
Using a web application as an example, the typical development flow would be:
- Deploy the exploded web application
- Access the application through a web browser
- Modify the code, compile the changes and have the corresponding class files saved to the correct location under the exploded application.
- Access the application through a web browser once again, and your changes will now have been applied and should be visible.
Note that FastSwap will not redefine any classes as soon as they have changed on the file system. The reason is because a change to one class file can affect other classes (e.g. when a method signature is changed) so all classes must be redefined at the same time. Therefore, the developer will need to tell FastSwap when it should start its operation. For web applications, this is accomplished by going through a servlet but for other applications the developer has to use the JMX interface for FastSwap. However, there is an Ant task accessing this JMX interface that can used to trigger FastSwap, as shown in the below example.
<project name='MyProject' default='all'>
<taskdef name='fast-swap' classname='com.bea.wls.redef.ant.FastSwapTask'/>
Where the parameters are:
- adminUrl: connection url
- user: user name
- password: user password
- server: managed server name
- application: deployed application name
Limitations & Further Reading
Even though FastSwap is an improvement over the default support found in the JDK there are still some limitations to what it can accomplish. For a list of these limitations as well as more information regarding FastSwap, please visit the following link: