JAX – RS Sub Packages Scan configuration Example

In this example we will see how Jersey will automatically discover the resources and providers in the selected packages and sub packages. This can be achieved by configuring properties in web.xml by using <init-param>  like as below.




1. Create Dynamic web project in Eclipse.




2. Write Java Resource classes.


3. Configure the Jersey Servlet and  <init-param> in web.xml

4. Run the Example

Deploy the application and try to see below scenarios.

NOTE : I have not included all the required jersey jars in the source code please download it from here and copy to lib folder.



If we  setting the  jersey.config.server.provider.scanning.recursive property as “true” in web.xml , Jersey servlet will recursively scan all sub-packages.

In the above scenario we can able access all the resources.





If we  setting the jersey.config.server.provider.scanning.recursive  property as “false” or empty in web.xml , Jersey servlet will not recursively scan all sub-packages it will scan only com.connect2java.department

In the above scenario we can able to access only one  resource i.e Department resource.




Download  Source Code
































Posted in webservices.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.