Friday, June 13, 2014

From tomcat to resin for development purposes

Tomcat reloads the application context when a change is detected in a class file in WEB-INF/classes directory. Resin reloads just the class out of the box which is more efficient. When combined with Dynamic Code Evolution VM (DCEVM) and HotSwapAgent you could cut on development time as the changes could include more serious refactoring like renaming methods.

Here is how I tested in resin an application previously running in tomcat which uses Spring, JPA and Hibernate.

Download resin open source version from http://caucho.com/products/resin/download/gpl#download

If you use log4j in your application then replace catalina.home for the full local path in log4j.properties (if you use log4j) for example:
log4j.appender.logfile.File=/var/log/resin/app.log
instead of:
log4j.appender.logfile.File=${catalina.home}/logs/app.log
Configure resin to load external resources like app.properties. In /etc/resin/resin.xml:
# /etc/resin/resin.xml
<resin xmlns="http://caucho.com/ns/resin"
xmlns:resin="urn:java:com.caucho.resin">
<class-loader>
<simple-loader path="/opt/tomcat/lib"/>
</class-loader>
Add special JVM flags as needed in resin.xml:
<cluster id="app">
<server-default>
<jvm-arg-line>-Xmx1024m</jvm-arg-line>
<jvm-arg-line>-XX:MaxPermSize=512m</jvm-arg-line>
</server-default>


If you are using special libraries loaded from the server container then copy them to resin lib directory:
cp -r /opt/tomcat/lib/jtds-1.2.4.jar /usr/local/share/resin-4.0.40/lib/
cp -r /opt/tomcat/lib/mysql-connector-java-5.1.26-bin.jar /usr/local/share/resin-4.0.40/lib/
cp -r /opt/tomcat/lib/tomcat-jdbc.jar /usr/local/share/resin-4.0.40/lib/
cp -r /opt/tomcat/bin/tomcat-juli.jar /usr/local/share/resin-4.0.40/lib/
Restart resin and look into the logs:
resinctl restart
tail -10f /var/log/resin/jvm-app-0.log
tail -10f /var/log/resin/app.log
Check changes to any class are efficiently reloaded (just the class changed should be reloaded). For example copying from maven target directory:
cp /path/to/workspace/app/target/classes/com/sample/web/OfficeController.class /var/resin/webapps/app/WEB-INF/classes/com/sample/web/
Resin is less permissive in terms of schema validations. Tomcat would allow "xsi:schemaLocation" in taglib tag to be all lowwer case. You can either correct taglibs or use the below in WEB-INF/resin-web.xml:
# WEB-INF/resin-web.xml:
<pre>
<web-app xmlns="http://caucho.com/ns/resin">
<jsp validate-taglib-schema='false'/>
</web-app>
If you have any problems testing resin look for answers or post your question in the resin forum.

No comments:

Followers