• Post Reply Bookmark Topic Watch Topic
  • New Topic

I need to clear doubt of Root resource classes scanning pattern of Jersey framework  RSS feed

 
Niiraj Patel
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have created sample project in eclipse and deployed it in tomcat.

I am using below jar files.

  • asm-3.1.jar
  • jersey-core-1.10.jar
  • jersey-server-1.10.jar
  • jersey-servlet-1.10.jar


  • below are classes.





    and




    my web.xml




    My Doubts
    1. How does Jersey framework inject/scan JAX-RS resources. if we don't provide class names explicitly
    2. Some docs says (links are provided below), we have to explicitly register package name to tell Jersey framework so it can scan those packages and inject AX-RS resources.

    Link 1 : https://jersey.java.net/documentation/latest/deployment.html#deployment.servlet.2
    Link 2 : http://docs.oracle.com/cd/E19776-01/820-4867/ggnxs/index.html


    even if I remove method getClasses() from class MyApplication, It is working fine. My doubt is how does it finds resource HelloWorldResource.java ?

    This is my Tomcat’s catalina.out logfile's snap:




    In above code I do not explicitly tell framework to register my class HelloWorldResource as I have commented getClasses method.


    Does it scan by annotation like @Path("helloworld") @Produces("text/plain") ?

    Thanks,
    Niraj

     
    Roger Sterling
    Ranch Hand
    Posts: 426
    Eclipse IDE Fedora Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I don't see an <init-param> in your web.xml. See http://www.mkyong.com/webservices/jax-rs/jersey-hello-world-example . Follow this example exactly step-by-step. Make mykong's code work. Then go back to your own code.

    Do you have a coach or mentor on your site? Have you attended training about Web Services ?

     
    Ulf Dittmer
    Rancher
    Posts: 42972
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Note that the documentation you linked to is for Jersey 2, not Jersey 1 (which is what you're using). Unless you have reasons to use the old version I advise to use the latest one (2.5.1 at the moment).

    Jersey 1 did indeed scan the classpath for resources automatically (which has nothing to do with injection, by the way). In Jersey 2 I have not been able to get this to work (although section 4.7.1.2 says it should work), and had to resort to the Application.getClasses approach you mention (section 4.7.1.1).
     
    Niiraj Patel
    Ranch Hand
    Posts: 47
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    exactly, This is my doubt.. even though I am not defining my JAX-RS resource explicitly, framework finds it. but how does it happen? links I provided in my post say that you have to define package or Application class through <init-param>, But I am not doing any thing and things work properly.

    Roger, Thanks for your help. I have cleared Java EE 6 Web Services Developer Certified Expert Exam.

     
    Niiraj Patel
    Ranch Hand
    Posts: 47
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Let me see by using newer version of Jersey. Thanks Ulf..
     
    Niiraj Patel
    Ranch Hand
    Posts: 47
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi, I have tried using new jersey version jaxrs-ri-2.5.1. But even if I don't provide any package name or class name, It takes all resources that I have implemented.

    To install new version I have to replace class-name in web.xml

    from



    to



    Now, My web.xml




    is there any idea how jersey scans your resources ?



     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!