1

Is there a framework or some solution for the following scenario.

I have a webapp running on say Tomcat server. When starting up my application I would like to download some jars that are located somewhere completely different. Like an external nexus server or something. In those jars is all my business logic that needs to be injected with spring.

Why do I want something like this? My application is installed on a lot of different locations. To easily have the latest version of the code on all installation I would like to only have to update 1 location and all applications are updated once they are restarted.

AHungerArtist
  • 9,332
  • 17
  • 73
  • 109
Xymon
  • 225
  • 1
  • 3
  • 8

2 Answers2

1

Your application will need to use a custom ClassLoader to do this.

The good news is that you don't have to write your own: you can use Java's built-in java.net.URLClassLoader. The bad news is that you will have to wire it into Tomcat, which may require some code.

This is an untested suggestion:

  1. Write a ClassLoader that extends Tomcat's WebappClassLoader
  2. Add a URLClassLoader member and initialize it in your constructor (or one of the LifecycleListener events like start())
  3. Override all methods to call the superclass's method of the same signature and also call the same method in the URLClassLoader you are using. The order in which you consult either super.whatever or urlClassLoader.whatever is up to you: read the servlet spec to determine how you want to do things
  4. Install your custom ClassLoader by defining a <Loader> in your web application's META-INF/context.xml file.

Head over to the Tomcat users' mailing list if you need help with any of the above.

EDIT 2014-11-04

Note that I think using a URLClassLoader to do this kind of thing is fragile, error-prone, and probably a Bad Idea. Instead, fix your deployment process so that updating your web application across a cluster is easier to do. You can use Tomcat's "farm web deployer" for such tasks, or use some other solution. But loading classes over the network is likely to complicate your life and result in some strange non-reproducible behavior in certain cases.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
0

Generally, this is done during deployment using an rsync script or some such to distribute the deployment artifacts to the cluster.

You might be able to configure the WebappClassLoader provided by Tomcat to load from remote locations.

PaulProgrammer
  • 16,175
  • 4
  • 39
  • 56