0

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 .warfile 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.

marc82ch
  • 1,004
  • 3
  • 11
  • 27

1 Answers1

1

If you have resources that your business layer needs, put them in the business layer jar.

Don't reach out to your web layer (via ServletContext) to retrieve things in an inner layer.

see: How to package resources, that are accessed directly , into a jar file

Community
  • 1
  • 1
Rob Conklin
  • 8,806
  • 1
  • 19
  • 23
  • Thanks Rob, makes sense. In fact, my project structure in Eclipse doesn't even allow me to reach out to web classes from my business layer (one-way project dependency). I'll consider putting everything on classpath root. – marc82ch Feb 09 '15 at 09:19