Re: Dev. env. question relating to classloaders

Scott Ferguson <[email protected]> Fri, 9 Jun 2006 13:51:36 -0700
Newsgroups gmane.text.xml.resin.user
Message-ID <[email protected]>
On Jun 9, 2006, at 10:14 AM, Tony Field wrote:

> Hi -
> I have a question regarding classloader order within the webapp.
>
> <executive summary>
> Given this classloader configuration in resin.conf's <web-app- 
> default> tag:
> 	<class-loader>
> 		<tree-loader path="${server.rootDirectory}/ext-webapp" />
> 		<compiling-loader path="WEB-INF/classes2" />
> 		<compiling-loader path="WEB-INF/classes1" />
> 		<compiling-loader path="WEB-INF/classes" />
> 		<library-loader path="WEB-INF/lib" />
> 	</class-loader>
> Can I have classes in jar files in WEB-INF/lib as well as in one of  
> my above WEB-INF/classes* folders, and rely on Resin to read only  
> the version of the class in WEB-INF/classes*, or will it read them  
> from /lib too?
> </executive summary>

Yes.  The class loaders will be searched in the order given.  Since  
your WEB-INF/classes is before the WEB-INF/lib, any classes there  
will take priority.

A related issue that people have run into is when they try to add the  
<class-loader> to the <web-app> block in the resin.conf, expecting it  
to override the default and to be used in the web.xml.  (It doesn't  
apply in your case because you're modifying the app-default.xml  
directly.)

In that case, you would need to use the new <prologue> tag, like:

<web-app ...>
   <prologue>
     <class-loader>
       ...
     </class-loader>
   </prologue>

The issue is that the <web-app-default> are concatentated in order,  
followed by the resin.conf's <web-app>.

So the final web-app looks like:

<web-app>
   ... // <prologue> stuff
   <class-loader ... for "WEB-INF/prologue">

   ... // stuff from app-default.xml's <web-app-default>
   <class-loader for WEB-INF/classes"/>
   <class-loader for WEB-INF/lib"/>

   ... // web.xml
   <servlet servlet-class="foo.MyClass" // only uses above class-loaders

   ... // resin.conf <web-app>
   // if resin.conf's <web-app> defined a <class-loader> it would go  
here and not
   // be visible to the above <servlet>

-- Scott

>
>
> <the whole story>
> I work on a large web application that has multiple supported  
> versions - so I have to have multiple development environments  
> floating around.  I usually have one global resin.home and a  
> server.root for each version.
>
> When I create a dev environment, I basically run our webapp  
> installer which creates a war file and deploys it, along with a  
> bunch of other files.  The war file is over 100MB so re-deploying  
> it while testing is not really high on my wish list.
>
> Our product contains quite a few jars.  It's broken into jars by  
> component, but also because we have some classes in a COM package  
> (this is an OLD product!) and the rest in a "com" package.  COM/com  
> issues have given us enough headaches already...
>
> I develop using IntelliJ IDEA, and its "make" functionality is  
> really nice and fast - it saves me having to recompile all of our  
> code, which takes a few minutes  even on my top of the line  
> laptop.  I usually just "make" my files into segregated directories  
> then run an ant script to bundle up my classes into the jar files  
> and move them into my webapp (which is running through IDEA as a  
> straight java application, not through the plugin, which is just  
> weird).
>
> Finally, on to my question.  I'd like to be able to "make" my  
> classes directly into my webapp's WEB-INF/classes folder (and I'd  
> set it up so I compile my COM classes into WEB-INF/classes2,  
> registering the classloader in resin.conf for the default-web-app's  
> classloader).  If I do this, do I have to remove my corresponding  
> jar file from my WEB-INF/lib folder?  I'm trying to streamline the  
> process of setting up a development environment that works  
> efficiently for me.
> </the whole story>
>
>
> Thanks very much!
> Tony Field
>
>