views:

140

answers:

2

I'm thinking something in lines of drupal multisite, where every site should have it's folder with themes, plugins and various static files. It turns out it's not quite easy to do with Java: classes must be in one place, tag files in other, static files in third, only jsp files can go wherever. classes and tags can be packed in jars, but how can I serve static files and jsps from jar? What is the best way to do such a thing?

Previous slightly related question: http://stackoverflow.com/questions/1499521/jsp-tags-outside-web-inf-tags

+1  A: 

By default in most servlet containers static files are served from anywhere apart from WEB-INF, same as JSPs (except not interpreted).

You can serve static files from a jar by writing a small servlet that loads them as resources (using e.g. Class.loadResourceAsStream()) and writes them out on the ServletOutputStream.

I don't know drupal, but it sounds like the equivalent in Java is the web application, which can be bundled up as a WAR archive (http://java.sun.com/j2ee/tutorial/1%5F3-fcs/doc/WebComponents3.html)

Jim Downing
That's the point, in Drupal you have one application with bunch of common code, and sites have separate data, different look, plugin here and there, but they share a lot. WAR file is entire application.
Slartibartfast
OK - I think I get what you're driving at. You could load your jars into the servlet containers class loader, which should then be available in the webapp, but the mechanism and your mileage will vary by servlet container. On the whole you're probably looking for (or developing) a framework (Tapestry, struts etc) to provide what you're after.
Jim Downing
A: 

Don't really understand your problem. I run multisites from same webapp, packaged as a single war.

My WAR is organized as follows,

myapp/WEB-INF
myapp/common
myapp/site1
myapp/site2

All the classes, TLDs are shared but 2 sites have totally different brand, themes etc. The site specific files go to their own directory. They share lots of static files like javascript and images. These files are stored under common and can be referenced using relative URL for each site, for example,

  ../common/images/cart.jpg

The whole thing is delivered as a single WAR and runs as a single app. The site is available at

http://example.com/myapp/site1

We also have an Apache front-end with mod_rewrite and the sites are also available as,

  http://site1.example.com
  http://site2.example.com
ZZ Coder
There is no place for slight variations between sites, so sites mus have exact same functionalities, not mostly same. Basically this is what we are going to do, and if site is different enough, we will have it in another app which is obviously not big deal.
Slartibartfast