JAX – RS Multiple Resource Packages configuration

In general we will have a lot of resource packages in our restful enterprise application , to configure all the packages we need to know the mechanism.

In this tutorial we will learn how to configure Multiple Resource Packages in restful enterprise application. <init-param> tag is used to configure Multiple Resource Packages in deployment descriptor which is web.xml like as below.

In above example we are configured two packages those are package1,package2 , like this we can configure many packages. we are using  ‘,’ as the delimiter in above shown example.  Instead of ‘,’ we can use below delimiters as well.

Let us have a look in to below example.

1. Create Dynamic web project in Eclipse.

 

RestfulMultiplePackageConfigExample_proj

2. Write Java Resource classes.

here we are implementing two resource classes(EmployeeResource and DepartmentResource ) which are in different packages.

 

 

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

here we configured two packages (com.connect2java.department,com.connect2java.employee) in web.xml , and we used ‘,’ as delimiter

 

 

4. Run the Example

OUT PUT:

RestfulMultiplePackageConfigExample

 

 

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

 

Download  Source Code

 

 

Posted in webservices and tagged .

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">