Speeding up JBoss 5 applicaiton deployment

I've mentioned before the trick of turning off the AOP scanner to quicken deployment, but I've found another way, that I like a lot better.

The delays in starting up are worst for CF apps, because they've got so many classes, and so you may have noticed that the more classes you've saved, the longer it takes.

For a while I had a script that cleared out the cfclasses folder before each start, but that was soooo hackish. More of a kludge, actually. Fine for development tho.

I've found that if you use a jboss-structure.xml file in your META-INF (I put it in my ear/META-INF), jboss will use it to determine what and where to deploy stuff, along with class paths and whatnot. This disables the recursive scanning jboss normally does, and makes startup times acceptable again.

Example 1 (ear file with libs in each war):

<structure>

    <context>
        <path name="railo.war" />
        <metaDataPath>
            <path name="WEB-INF" />
        </metaDataPath>
        <classpath>
            <path name="/railo.war/WEB-INF/lib" suffixes=".jar" />
        </classpath>
    </context>

</structure>

Example 2 (ear file with consolidated libs folder):

<structure>

    <context>
        <path name="widgets.war" />
        <metaDataPath>
            <path name="WEB-INF" />
        </metaDataPath>
        <classpath>
            <path name="/lib" suffixes=".jar" />
        </classpath>
    </context>

    <context>
        <path name="sprockets.war" />
        <metaDataPath>
            <path name="WEB-INF" />
        </metaDataPath>
        <classpath>
            <path name="/lib" suffixes=".jar" />
        </classpath>
    </context>

</structure>

multiple CF instances in an EAR

To continue on my series about deploying CF apps, I'm going to cover a nice method of doing multiple instances, using an EAR deployment.

You'll want to start off with your EAR folder. For this example we'll use Railo, cuz it's the best, but the others work similarly.

I'll call this EAR railo.ear. So I make a folder called railo.ear, and within it I create a folder called META-INF, and then inside that I create a file called application.xml.

Into railo.ear/META-INF/application.xml I put this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN" "http://java.sun.com/j2ee/dtds/application_1_2.dtd">
<application id="Application_ID">
<display-name>RailoApps</display-name>
<description>Railo Applications</description>
<module id="widgets">
<web>
<web-uri>widgets.war</web-uri>
<context-root>/widgets</context-root>
</web>
</module>
<module id="sprockets">
<web>
<web-uri>sprockets.war</web-uri>
<context-root>/sprockets</context-root>
</web>
</module>
</application>

You're probably wondering what the widget and sprocket wars are. They are the names of our (in this example) Railo CF applications (widgets.com and sprockets.com).

We'll start off with a normal Railo war install. You've got WEB-INF/web.xml and a bunch of libraries in WEB-INF/libs. What we're going to do is move the {railo.war}/WEB-INF/libs folder to our EAR folder ({railo.war}/WEB-INF/libs becomes railo.ear/libs). Next we'll rename the railo.war to widgets.war, and move it under our EAR (ex.: railo.ear/widgets.war). It will be a pretty lonely folder, there's nothing in it besides WEB-INF/web.xml.

Now, I like using one web admin for all the instances (DSNs and whatnot only need to be configured once, and any CF apps in the ear will pick them up), so this is how I change the WEB-INF/web.xml file configuration param for Railo to achieve this: configuration ../META-INF/railo-web/ Configuraton directory

This tells Railo to store it's "web" configuration information in railo.ear/META-INF/railo-web.

Next we copy the widgets.war directory to sprockets.war. That's it. (Make as many copies as you want (we're sticking to widgets and sprockets), just give them unique directory names. Each one of these will be an instance. Good thing we're using one configuration location for all of them, neh?)

I like storing the configuration with the EAR, in the future this might come in handy...

Anyways, now move that EAR into your application server's deployment directory, and fire up your container/server.

If all goes well, you should see some output about railo generating it's flex stuff and whatnot (almost all of it will end up in railo.ear/libs), and see the widgets and sprockets contexts load up.

If you really did see them load up, then you can browse to each application using a URL format like this: http://your.host.name:8080/widgets and http://your.host.name:8080/sprockets. (See, the name of the directory becomes the context name. Neat, nuh?)

Assuming that worked, you're done! (with this part... next comes hooking them up to Apache.)

installing multiple CF engines into one EAR for compatibility testing

We're going to cover installing cfusion, opendb, and railo into a single EAR, for compatibility testing and whatnot.

This is most useful on a system with softlinks (symlinks), so windows users are kinda hosed (yeah yeah, MS has "had them" since 2K-- let's not go there).

You don't *need* the symlinks, but only Railo seems to be able to pick up an initial request to a mapped resource-- the others need at least one physical file first (correct me if I'm wrong, people) -- so you're stuck with multiple copies of your code, otherwise.

Now for the meat: there's not much.

Create an ear for your engines (ex.: cfengines.ear) -- this is an empty folder, for now (yes, with the dot -- on windows systems, you can use a dash too, I reckon -- bleh).

Next create the META-INF folder within the cfengines.ear folder. Case matters.

Then create your application.xml file in the META-INF folder. (Ex.: cfengines.ear/META-INF/application.xml) put something like this into it:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN" "http://java.sun.com/j2ee/dtds/application_1_2.dtd">
<application id="Application_ID">
<display-name>CFEngines</display-name>
<description>CFEngines</description>
<module id="railo">
<web>
<web-uri>railo.war</web-uri>
<context-root>/railo</context-root>
</web>
</module>
<module id="cfusion">
<web>
<web-uri>cfusion.war</web-uri>
<context-root>/cfusion</context-root>
</web>
</module>
<module id="openbd">
<web>
<web-uri>openbd.war</web-uri>
<context-root>/openbd</context-root>
</web>
</module>
</application>

And then, well, start your engines! (as in, start downloading them).

After you've got the ones you need (you're looking for WAR files, obviously), you're going to want to put them in expanded format within your EAR.

We like exploded format so that we can do live editing of CF files. This means you unzip the WAR file (it's just a zip, so you can change the name to railo.war.zip, for instance) into a .war folder in the ear folder.

Ex: cfengines.ear/openbd.war/, cfengines.ear/cfusion.war, etc..

If you're thinking by now that this sounds lot like my "how to install Railo as an EAR", you're pretty observant.

Move the ear into your deploy folder (for jboss, it's {jboss.home}/servers/{server}/deploy, for instance) and start your container. That's it!

Yes, it's really that easy.

This will provide you with http://your.host.here/railo for railo, http://your.host.here/openbd for openbd, and http://your.host.here/cfusion for Adobe CF (admin would be at http://your.host.here/cfusion/CFIDE/administrator/index.cfm, for example -- the index.cfm at the end is important!).

The only down side is that these CF engines ('cept Railo) need the CF files in their WAR directory. At least one file-- after you hit a "real" one, you can take advantage of mappings and whatnot from anywhere on your drive.

If this doesn't seem to make sense, try it out, you'll see what I mean.

I'll cover the Apache URL-rewriting from this point, in another entry.

BlogCFC was created by Raymond Camden. This blog is running version 5.9.3.000. Contact Blog Owner