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?
2 Answers
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:
- Use a
ContainerLifecycleListener
to get a reference to the container - Check folder for update, load all new jar files
- Scan for resource classes
- Create a new
ResourceConfig
and add all resources (old and new) - 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.
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.

- 11
- 1