I'm developing a Java web application of quite some scope. It has many modules, uses many external libraries to do stuff and works together closely with a set of standalone batch applications (cron jobs) that generate PDFs, invoices, batch process log files, do FTP uploads to partners on a regular basis and all that kind of stuff.
My code base is divided in
- Web/Batch layer
- Business layer
- Common model layer
- DAO layer
The first layer contains two packages .web
and .batch
. The first containing all servlet related stuff and the latter all batch programs with main(String[] args)
methods. Both worlds use the common and the business layer to do their job, often even the same methods (e.g. loadUser()
, storeUser()
, etc.)
Now I have a broad question:
What is an appropriate deployment strategy for this?
given that I want to deploy my webapp as a .war archive, and the batch programs should be invokable from UNIX cron
.
and a very specific one:
How would I go about loading resources from the business layer?
When thinking about the webapp, I'd store config files, like an Apache FOP config file and .xsl
transform files for generating invoice PDFs, etc. inside the WEB-INF
directory, probably some subdirectory, or in the .war
file META-INF
?
However, in the business layer, where these things are needed, (e.g. service method generateInvoicePDF(transaction)
), I can't use the servletContext to grab resources. And in batch programs, there's not even a servletContext and a WEB-INF
directory!
How do you guys do that? Do you really only need resources in the web layer? Or would you put all those files into the classpath root and use ClassLoader.getResource()
? I'd end up with quite some assorted files there. Don't like that. Or only config files in classpath root and .xsl
into some external hardcoded folder in the file system (not very portable)?
Any guidance and experience from other projects will be appreciated.