[opencms-dev] Where to put Beans?

Christoph Schönfeld cschoenfeld at sylphen.com
Fri Nov 17 09:57:50 CET 2006


Hi,
> 2.  The classpath in operation for OpenCms JSP pages includes class/ folders
> 'in modules' and JARs in lib/ folders 'in modules'.  'In modules' means
> 'contained in any folder called /system/modules/modulename'.  OpenCms trawls
> through all module folders under /system/modules and ensures that at JSP
> execution time, all such locations are part of the classpath.  I'm not sure
> of the precise mechanism, but that's the effect of it.
>   
If you want custom Java code you might consider (A) to create a module. 
A module can contain classes in its /system/modules/yourmodule/classes/ 
directory and JARs in its /system/module/yourmodule/lib/ directory (both 
in the VFS).

The ClassLoader of the web application (called Webapp ClassLoader in 
Tomcat speak) is unable to load classes and resources from these 
locations because they are not standard locations. As defined in the 
Servlet Specification, the standard locations are WEB-INF/classes and 
WEB-INF/lib.
There are two options for a Web Application to make files in 
non-standard locations available to the Webapp ClassLoader at runtime:
1. Extend the Webapp ClassLoader to support loading of classes, JSPs and 
resources  from the VFS
2. Less elegant but much simpler: Copy classes and resources from 
non-standard locations to the standard locations.

OpenCms takes the second approach. It copies your module files whenever 
you start the publish operation. This is called export in OpenCms speak 
(files are exported from the VFS to the RFS on disk). You can see 
"export points" in the module management screen. OpenCms exports any 
path which has such an export point.

You can of course avoid all this by (B) not creating a module at all. 
Instead you would put your files directly in the standard locations. 
Anyway, it is recommended to create a module at least for your JSPs, 
images etc. It makes it easy to handle all files as a single package.
> 3.  So to develop your own code, best to do so by putting classes and
> libraries in /system/module/modulename - and then your stuff should be found
> automagically.
>   
As mentioned above, you have to start the publish operation in order to 
make your files visible to the Webapp Classloader. Any change to a class 
or resource file already loaded once requires a restart of the OpenCms 
Webapp. Changes might be picked up automatically if you configured the 
Webapp as reloadable. Otherwise you have to restart it manually after 
publishing.
I am not yet sure about the advantages of A or B. If OpenCms took the 
first approach, A would certainly make more sense. It would simplify 
development because OpenCms could throw the ClassLoader away each time 
the module changes. There would be no need to restart OpenCms itself if 
only a module changed. But since OpenCms currently takes class loading 
approach 2, that's future talk.

Best regards,
Christoph



More information about the opencms-dev mailing list