Showing posts with label App Engine. Show all posts
Showing posts with label App Engine. Show all posts

AppEngine, JRebel and Eclipse - Getting them to work together

Wednesday, 29 September 2010

6 comments
I recently started using JRebel for development, but initially I had a bit of trouble getting it to gel with the App Engine / Eclipse setup. After an email or two with the guys at Zero Turnaround I finally got it to work, and it's well worth the effort. Here is a guide for what you need to do...

  1. Install JRebel, the latest version for your platform.

  2. Get into Eclipse and install the JRebel Eclipse Plugin using the "Install New Software..." link under the Help menu, and add the JRebel Update site...

    http://www.zeroturnaround.com/update-site

    I specified the "JRebel Eclipse Debugger Integration" and "JRebel Eclipse Integration only" components.

  3. Specified the jrebel.jar in Eclipse / JRebel preferences. (Mine was in my C:\Program Files\ZeroTurnaround\JRebel\jrebel.jar folder.

  4. The installation Wizard provided with JRebel provides you a guide to get it working in Eclipse. Make sure you go through those steps. (...adding org.zeroturnaround.* etc in Eclipse preferences)

  5. Modified the dev_appserver.cmd, which on my PC sat in

    C:\dev\eclipse\eclipse-SDK-3.6-win32\plugins\com.google.appengine.eclipse.sdkbundle.1.3.7_1.3.7.v201008311427\appengine-java-sdk-1.3.7\bin\dev_appserver.cmd

    Here is it's contents:

    @java -cp "%~dp0\..\lib\appengine-tools-api.jar" ^
        com.google.appengine.tools.KickStart ^
    --jvm_flag=-javaagent:%REBEL_HOME%\jrebel.jar --jvm_flag=-noverify ^
           com.google.appengine.tools.development.DevAppServerMain %*
    


  6. Now you need to add this to the VM Arguments for your Run configuration for your App Engine application:
    -javaagent:/opt/jrebel/jrebel.jar -noverify
    Again, make sure this points to your jrebel.jar location.

  7. Once you've modified the VM Arguments in the app run config then you should see the JRebel text appear in the console.

  8. By the way, you don't need to execute your application in Debug mode to get JRebel to work. If you modify a file in Debug mode you'll still get the "Hot Code Replace Failed" message.

  9. To test I simply booted up the app, and added a method to a class and called it - You'll see a message in the console saying that JRebel is reloading the class.

Now enjoy a considerably quicker method of developing / deploying App Engine apps. $59 bucks is well worth it!

I'm hoping the team at Zero Turnaround turn their attention to Android's Dalvik VM next. JRebel would be of HUGE benefit to developing Android apps and I'm sure with the amount of Android developers out there at the moment it would be a big money spinner for them too.

Slow initial start-up time in your Java App Engine Application?

Saturday, 24 April 2010

2 comments
A lot of developers have been complaining about slow start-up times of their applications in app-engine production recently on the App Engine issues list. 10-20 second start-up times is not uncommon causing long waits for app users and potential errors in some applications. This is made worse by applications that rely on frameworks that do quite a bit on start-up. With app engine your application doesn't get a permanent JVM instance like you would usualy so this means that if there's been no activity for a while the JVM goes cold so your app will have to start-up again on the next request.

The good news for people suffering with this issue (and that is all App Engine developers I would say) is that the GAE team has accepted the issue and introduced it into their roadmap - "Ability to reserve instances to reduce application loading overhead". Personally I really won't mind paying for my own JVM instance if it's not too expensive, and I would guess that this is probably the direction the GAE team will go.

My "quick-fix" (or hack) for this issue at least until the GAE team sorts it out, is to ping your app every few minutes to keep the JVM "warm". Here I've created a blank servlet that gets called by the AE background cron.xml tasks every few minutes...

web.xml:
...
<servlet>
    <display-name>BlankServlet</display-name>
    <servlet-name>BlankServlet</servlet-name>
    <servlet-class>my.package.BlankServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>BlankServlet</servlet-name>
    <url-pattern>/blank.html</url-pattern>
</servlet-mapping>
...

BlankServlet.java:
public class BlankServlet extends HttpServlet
{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    {
        // Nothing needed here.
    }
}

cron.xml:
<?xml version="1.0" encoding="UTF-8"?>

<cronentries>
    <cron>
        <url>/blank.html</url>
        <description>Ping a blank page to keep the JVM warm</description>
        <schedule>every 5 minutes</schedule>
    </cron>
</cronentries>
You could of course ping your main welcome page instead but you might have some code in your pages that you might not want to be executed by an automatic process - maybe your Google Analytics javascript for example.