1

I want to implement a plug and play web service were we can just define different resources in different jar and just put those jars in the resources folder of web server and server loads resource classes and registers them with jersey.I don't want to stop the server for a resource update or adding a new resource path. Is there a way to do the register resources with jersey at runtime? Or do you suggest another pattern for handling this problem?

armin
  • 1,985
  • 6
  • 38
  • 52

2 Answers2

4

You can not modify a ResourceConfig after you started it, but you can create a new one with updated values and then reload the container with the new configuration.

There is an official example that shows how to watch a file for changes and reload the container: https://github.com/jersey/jersey/tree/master/examples/reload

The example assumes classes are already loaded in the class path. It should be easy to modify the example to watching a folder and loading new jar files. See How to load a jar file at runtime

The basic steps are:

  1. Use a ContainerLifecycleListener to get a reference to the container
  2. Check folder for update, load all new jar files
  3. Scan for resource classes
  4. Create a new ResourceConfig and add all resources (old and new)
  5. Call container.update(newResourceConfig) to use your updated configuration

I wouldn't recommend to implement something like unloading jars or reloading existing classes - you would have to deal with a lot of potential problems. If you need reloading, look for existing solutions like jrebel vm or maybe OSGi.

Community
  • 1
  • 1
kapex
  • 28,903
  • 6
  • 107
  • 121
-1

I have used @Path("/{subResources:.*}") this return any possibility

and uses this attribute @Context private UriInfo uriInfo; to get values

and get the subResources value at method with String path = uriInfo.getPathParameters().getFirst("subResources");

with this string can split or can use regex.

Heck
  • 11
  • 1