One of the cool new things I learned about here at the ODTUG 2009 conference is the fast swap feature in WebLogic Server 10.3 and above. So far, Application Server features have had limit use in my little development world, but this is one that may have quite some value for me, as I am developing my web applications in JDeveloper and constantly deploying, running and testing them. This feature will considerably shorten those development cycles!
The fast swap feature makes it possible to have classes that are changed and recompiled in JDeveloper immediately redeployed on WLS, without actually redeploying the entire application. By setting a single configuration option in a configuration file and configuring the output path for the compiler in JDeveloper I can shorten most of the development-compile-deploy-test cycles by eliminating the deploy (and application restart) step.
Note that there are some (minor) limitations to the type of changes that can be hot swapped. Also note that the fast swap only applies to class files – and not to one of the many XML files that are part of most web applications today. The fast swap has already been available much longer in the case the application was running in Debug mode (also known as hot redeploy). However, this type of hot redeploy is much more restrictive with regard to the code changes it will accept (only changes within methods).
So how does it work?
The simplest steps to see this feature in action are the following:
1. Start JDeveloper 11g
2. Create a new Web Application
3. Create a Servlet
Have the Servlet return some value
4. Configure the <fast-swap> element in the weblogic.xml file:
* from the ViewController project node in the application navigator select the menu option New; select the General, Deployment Descriptors category and select on the right hand side the WebLogic Deployment Descriptor item.
* in the wizard that appears, select the option weblogic.xml and click Finish
* in the weblog.xml file that is now added to the project, add the following XML fragment:
<fast-swap> <enabled>true</enabled> </fast-swap>
5. Run the Servlet (which will compile the application, start WLS, deploy the application and start the browser with the URL where the application (servlet) can be accessed
See the result appearing in the browser
6. WebLogic Server will only be able to spot changed class files in the deployment directory where the web application has been exploded. You will have to locate the system188.8.131.52.31.51.56\o.j2ee\drs directory (the exact number sequence after system can vary with the exact version you are using); in that directory, you will find a directory that is named as your web application is, and inside that directory there is a webapp directory that contains WEB-INF with a classes subdirectory. That classes directory (in my case that is system184.108.40.206.31.51.56\o.j2ee\drs\WLSFastSwap\WLSFastSwap-ViewController-webapp\WEB-INF\classes) is where during deployment the application’s classes were deployed to and that is where WebLogic will check for hot swappable classes.
Now that you know the location of your (deployed) classes, change the Project Output Path for your ViewController project. From the context menu on the project, select Project Properties. Select the Project Source Paths node. On the bottom of the page that opens, you can set the Output Directory. Set it to the <long name>\WEB-INF\classes directory you discovered just before. Now any class gets compiled into that directory where it can be detected by WebLogic Server.
7. Change the result returned from the Servlet
Make some changes to the code in the Servlet Class to make it return a different value than before. Note: the fast swap not only applies to the Servlet Class but to any class that is deployed in your application.
8. Compile the Servlet
You may check whether the compiled class is written to the ‘exploded deployed’ classes directory. If you can see it appearing there, then so can WebLogic Server.
9. Refresh the browser => the new output is visible, even though we did not redeploy the web application
Note: there are some limitations for the changes that fast swap will support.
Documentation on WebLogic Server 10.3 – Fast Swap