The Source for Java Technology Collaboration
User: Password:



Felipe Leme

Felipe Leme's Blog

Setting a lightweight JBoss server for web development only

Posted by felipeal on October 27, 2004 at 09:04 PM | Comments (11)

A couple of months ago, I had to implement a custom LoginModule to be used by a J2EE application running primarily on JBoss 3.0.8 (bundled with Tomcat 4.1.24). While developing it, I had to restart JBoss on every new progress, in order to test the changes. As my desktop was just a poor Pentium III with 512MB, running all sort of geek stuff (mozilla, emacs, eclipse, many shells, gaim, openoffice, etc...), JBoss started in about 2 minutes and stopped in another 1:30 minutes, totalizing long 4 minutes for every iteration!

So, as a good 'lazy developer', I decided to spend some time cleaning JBoss (I was using the default configuration, which loads a lot of stuff that didn't matter to my LoginModule, such as EJB container, Messaging server, EAR deployet, HSQLDB, etc...) and recover that time during each iteration. So here's what I did:

1.Started copying the minimal server configuration to a new configuration called web:

cp -a ${JBOSS_HOME}/server/minimal ${JBOSS_HOME}/server/web

2.Copied the tomcat41-service.xml from the default configuration:

cp ${JBOSS_HOME}/server/default/deploy/tomcat41-service.xml ${JBOSS_HOME}/server/web/deploy

3.Copied some JARs from default's lib:

cd ${JBOSS_HOME}/server/default/lib; cp jboss.jar tomcat41-service.jar jbosssx.jar ../../web/lib

At this point, the new server was already ready for web development, and starting as a breeze:

~felipeal# ${JBOSS_HOME}/bin/run.sh -c web
...
...
00:25:43,280 INFO [Server] JBoss (MX MicroKernel) [3.0.8 (CVSTag=JBoss_3_0_8 Date=200306050849)] Started in 0m:7s:303ms


Now I needed to set the authentication stuff:

4.Added new MBeans on jboss-service.xml:
<mbean code="org.jboss.security.plugins.SecurityConfig"
	 name="jboss.security:name=SecurityConfig">
    <attribute name="LoginConfig">jboss.security:service=XMLLoginConfig</attribute>
  </mbean>
  <mbean code="org.jboss.security.auth.login.XMLLoginConfig"
	 name="jboss.security:service=XMLLoginConfig">
    <attribute name="ConfigResource">login-config.xml</attribute>

  </mbean>
  <mbean code="org.jboss.security.plugins.JaasSecurityManagerService"
	 name="jboss.security:service=JaasSecurityManager">
    <attribute name="SecurityManagerClassName">
      org.jboss.security.plugins.JaasSecurityManager
    </attribute>
  </mbean>


5.Created the login-config.xml on web/conf, adding my custom LoginModule:
<?xml version='1.0'?>
<!DOCTYPE policy PUBLIC
      "-//JBoss//DTD JBOSS Security Config 3.0//EN"
      "http://www.jboss.org/j2ee/dtd/security_config.dtd">

<policy>
<!-- put my login module setup here - don't remember the details :-) -->
</policy>
6.(optional) If running on JDK 1.3, it's also necessary to copy jboss-jaas.jar and xalan.jar to lib:
cd ${JBOSS_HOME}/server/default/lib; cp jboss-jaas.jar xalan.jar jbosssx.jar ../../web/lib

That's it: the new server was ready for quick development cycles (startup and shutdown in about 20s!)


Now, back to present day, I had to configure JBoss 3.2.5 to run as a web-server only (I know I could use a pristine Tomcat 5.0.x, but it had to be JBoss) on my home server, which is also an old PIII, again running a lot of stuff (xinetd, mysql, tomcat, X, eclipse, emacs, gaim, evolution, mozilla, etc...).
The steps changed a little bit, but fortunately not that much:

1.Start copying the minimal configuration:

cp -a ${JBOSS_HOME}/server/minimal ${JBOSS_HOME}/server/web

2.Instead of copying tomcat4-service.xml, copy the whole jbossweb-tomcat50.sar directory:

cp -a ${JBOSS_HOME}/server/default/deploy/jbossweb-tomcat50.sar ${JBOSS_HOME}/server/web/deploy

3.Copy some JARs from default's lib:

cd ${JBOSS_HOME}/server/default/lib; cp jboss.jar jboss-j2ee.jar jbosssx.jar ../../web/lib

4.Assuming you don't need transactions neither Tomcat's CachedConnectionValve, comment out the following lines on ${JBOSS_HOME}/server/web/deploy/jbossweb-tomcat50.sar/META-INF/jboss-service.xml:
    <depends>jboss:service=TransactionManager</depends>
    <depends>jboss.jca:service=CachedConnectionManager</depends>

That's it, now you have a 'clean' JBoss 3.2.5 web server ready to roll! Note that this new server is not that faster proportionally (in my case, the startup is 30s against 1m from the default configuration), but it still saves you a good ammount of resources (memory, threads, file handlers, etc...).

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Clever! I have a similar tip. You mention that it takes 1:30 for a clean shutdown. Rather than shutting JBoss down properly, kill the process. Then delete the following directories (assuming default configuration):
    /server/default/data/
    /server/default/work/
    /server/default/conf/
    /server/default/log/

    This will speed up shutdown quite a bit. Of course, by deleting these directories JBoss will have to recompile each of your JSP pages and unzip your ears and wars once more.

    To kill a process instead of shutting it down, type:
    ^Z
    kill -9 %

    Posted by: jessewilson on October 28, 2004 at 07:26 AM

  • If you leave the jmx-console enabled, you could reload the JMX beans you need on each cycle instead of restarting the whole server. That'd work for most scenarios

    Posted by: analogueboy on October 28, 2004 at 02:18 PM

  • Why don't you just use Jetty as your webserver despite of reinventing the wheel adapting JBoss+Tomcat just to serve web stuff?

    Posted by: danielqo on October 28, 2004 at 09:29 PM

  • jessewilson: your trick would help to speed up the shutdown, but the startup would still be slow :-(

    analogueboy: that's an interesting idea too. I will try it next time (combined with the stripped server)

    Posted by: felipeal on October 28, 2004 at 09:32 PM

  • Daniel,

    At that time I had to use that version of JBoss. Maybe using Jetty would make things easier, but the point of this blog was to explain what should be stripped/copied in order to get Tomcat working (and probably I would need similar steps to get it working with Jetty).

    But I will try it next time...

    Posted by: felipeal on October 28, 2004 at 09:53 PM

  • Why didn't you just use Tomcat?

    Posted by: crazybob on October 29, 2004 at 11:07 AM

  • Bob,

    I couldn't use Tomcat the first time because I was developing a LoginModule to be used specifically by JBoss (besides, Tomcat uses Realms for authentication; it has some sort of LoginModuleRealm, but that was not what I needed).

    Now, for this new project, I could use Tomcat. The main reason I didn't was because I was planning to re-enable the HSQLDB database and use it for tests (but haven't had the time to try that yet). In fact, I typically use Tomcat for web-development, configuring a context on server.xml pointing to my workspace, instead of deploying a WAR on webapps every time.

    Anyway, I think you guys are missing the point of the blog: I didn't say this was the best option, I just wanted to share how I did it :-(


    Posted by: felipeal on October 29, 2004 at 11:29 AM

  • I didn't intend to criticize. Just curious as to what JBoss features you were using.

    Posted by: crazybob on October 29, 2004 at 11:41 AM

  • Ok, no stresss. In our case, must of the developers use other features like the EJB and Messaging containers, although a few people needs only the web container.

    Posted by: felipeal on October 29, 2004 at 11:47 AM

  • If you create a war file out of your deliverable and drop in into the deploy directory for your context (hot-deployment) you need not even restart the server each time (assuming all the dependencies are bundles within the war file). Just drop the new war versions in that location and test.

    Posted by: m0rph on November 01, 2004 at 07:06 AM

  • hi,

    i was working on tomcat for my JSP/Servlet application now i shift my project to JBOSS i wanna know that how i use JBOSS as development server, that if i change JSP then i dont need to deploy changed WAR to JBOSS, i just refresh my page and get result.??

    Posted by: emmi12345 on July 13, 2005 at 12:30 AM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds