开发者

How do I reload servlet classes without restarting my web application?

I want to reload just my web layer classes without reloading my service layer classes (which take longer to initialize and change less frequently). There are no references from my service layer into the web layer and I can create a开发者_如何学Go whole new instance of the web layer without problems.

I can conceive of a solution involving complicated class-loader tricks to isolate the web layer in its own class-loader and I think this is probably the only way to do this so what I'm asking is, is there a library out there which does this?

I know about JavaRebel - I don't need that much power and I'm really looking for a more lightweight free solution.


If your web layer is separated from the service layer would it be possible for you to deploy them as to separate applications? Then the web app could be reloaded as often as necessary.

In case the reason for reloading of the webapp is changes in configuration, then move properties etc away from WEB-INF-folder (as they normally are not reloaded/reloadable). Ideas for handling reloadable configs etc can be found in Spring and FreeMarker


I think you will end up wasting more time developing the feature than actually developing the webapp. Just life with it, that's where you're paid for. I can imagine that this may be frustating for PHP-originated developers who used to F5/refresh on every new line of code... However, it also depends on appserver you're using. Most just supports hotdeploys. Ensure that yours is configured to do so as well, usually the IDE should already take care over this (at least, mine does: Eclipse + Tomcat6 or Glassfish3).

It may also depend on the appserver in question whether hotdeploys are fast and/or succesful. I've experienced that Glassfish -although it's a slow starter- is extremely fast in hotdeploys. I like it. Tomcat is a bit slower in this and also not always succesful (e.g. old stuff/garbage still in memory and so on).


Maybe this solution is useful for you: http://blog.redfin.com/devblog/2009/09/how_to_set_up_hot_code_replacement_with_tomcat_and_eclipse.html


Not sure this will solve your problem, but if you can instantiate a whole instance of web layer easily , maybe you can create a method that does that called reloadWebLayer(), for example. Then add a button to an admin page that calls reoladWebLayer() when clicked?

If you need it to reload automatically, you could set a timer and call reloadWebLayer() every x seconds, or maybe you could write a file listener that runs reloadWebLayer() whenever a file on the classpath changes?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜