views:

360

answers:

1

I have a web app: MyApp.war, inside it, I have a jar file: WEB-INF/lib/PublicJar.jar

  • I want client applications to be able to download that jar like a web resource. e.g http://theserver.com/myapp/jars/PublicJar.jar

  • I want the web application to be able to compute the hashcode of the jar file to see if it has changed, so clients know if it needs to reload it.

Can this be done?

+2  A: 

Resources inside WEB-INF cannot be served directly to the client. If you want to do that, you need to write a servlet/controller to extract it as a ServletContext resource and feed it to the http response.

Is PublicJar.jar also used by your application itself? Could you not move it out of WEB-INF, or maybe bundle two copies of it in the WAR, one under WEB-INF (for internal application use), and one for downloading?

skaffman
PublicJar.jar is used by the application, as it loads resources out if it (via spring's resource loader classpath:public/resource.xml). Actually PublicJar.jar contains only resources - its just a jar to keep them all together as self contained unit.
Justin
In that case, move the jar out of WEB-INF, Spring will still be able to load using a ServletContextResource. Once out of WEB-INF, clients will be able to access it directly.
skaffman
Thanks! The spring resource loader totally helped. I went with the servlet approach because I already use HttpInvoker for the clients so I added a service method: byte[] readPublicJar() - quick + dirty. If PublicJar ever gets big, i'll have to move it to the servlet context rather than read it in from the servlet.
Justin