java - Dynamically loading jars from remote location -
Is there a framework for this scenario or some solution?
I have a webpage that is running when I say Tommet Server, when my application starts, I would like to download some jars which are completely different. Like all external Nexus servers or some things, all those commercial jargons in Jars are required for injection with spring.
Why do I need something like this? My application is installed at very different locations. To easily install the latest version of the code on all installations I would like to update only 1 location and all applications are updated once it is restarted.
To do this, use your custom class load loader
Will be required.
The good news is that you do not have to write your own: You can use Java's built-in java.net.URLClassLoader
. The bad news is that you have to wire it in a tomcat, for which some code may be required.
This is a recommended suggestion:
- A
classloader
that extends theWebappClassLoader of Tomcat
- Add a
URLClassLoader
and start it in your constructor (orLifecycleListener
Start ()
) events like < / Li>- Override all methods to call the superclass method of the same signature and call the same method as the URLclassloader you are using. In order to consult you either
super.whatever
orurlClassLoader.whatever
, read सर्वोलेट स्पैक to determine how you want to work inMETA-INF / context.xml
file in your web application& lt; Loader & gt; Define your custom
.classload loader
by defining - Override all methods to call the superclass method of the same signature and call the same method as the URLclassloader you are using. In order to consult you either
If you need help with any of the above, then proceed.
EDIT 2014-11-04
Note I think using a URLClassLoader
to do this is fragile, Error prone, and maybe a bad idea, instead, fix your deployment process so it's easy to update your web application across a cluster. You can use Tomcat's "Fire Web Depler" for this kind of work or you can use some other solution. But loading classes on the network can make your life difficult and results in some strange non-reproducible behaviors in some cases.
Comments
Post a Comment