Hello World JAX-RS Jersey Example with Maven

Connect with

1. Create Maven project

Maven web project can be created by different way. I have chosen via Eclipse

1. File -> New -> Others -> Maven -> Maven Project -> click Next -> choose maven-archetype-webapp
or
2. In Eclipse IDE create “Dynamic Web Project” and select Project -> write click on project -> select Configure -> Convert Maven Project.

2. Environment used as:

  • JDK 7
  • Eclipse Luna 4.4.1
  • Tomcat 7
  • Maven 3.2.3

3. Project folder structure as

Hello World Jersey Project structure
Hello World Jersey Project structure

4. Maven pom.xml

Add dependency of jersey server specific jar of your suitable version. Maven pull required dependency from specified repository.


	4.0.0
	com.mysoftkey.jaxrs
	jerseyhelloworld
	war
	0.0.1-SNAPSHOT
	jerseyhelloworld Maven Webapp
	http://maven.apache.org

	
		1.9
	

	
		
			com.sun.jersey
			jersey-server
			${jersey.version}
		

	

	
	
		src/main/java
		
			
				maven-compiler-plugin
				3.1
				
					1.6
					1.6
				
			
			
				maven-war-plugin
				2.4
				
					WebContent
					false
				
			
		
	

5. web.xml

We need to add ServletContainer entry in our Deployment structure i.e. web.xml here. And package we need to specify in init-param , where our services class resides. When web server tomcat start, the instance of ServletContainer loads into servlet container.



  jax-rs
  
  
	jerseySerlvet
	com.sun.jersey.spi.container.servlet.ServletContainer
	   
		com.sun.jersey.config.property.packages
		com.mysoftkey.jaxrs
	   
	   1
	

	
		jerseySerlvet
		/*
	
	
  
    index.jsp
  

6. HelloWorldService class


package com.mysoftkey.jaxrs;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

/**
 * This is hello jersey JAX-RS implementation.
 * 
 * @author Ranjeet Jha
 *
 */
@Path("/hello")
public class HelloWorldService {

	/**
	 * This is simple jersey hello world example
	 * 
	 * @param msg
	 * @return
	 */
	@GET
	@Path("/{param}")
	public Response helloJersey(@PathParam("param") String msg) {
 
		String output = "Hello, Jersey " + msg;
		return Response.status(200).entity(output).build();
	}
	
}

7. Run application

open browser and type url as : http://localhost:8080/jerseyhelloworld/hello/ranjeet
output on browser as :

Hello, JAX-RS Jersey ranjeet

8. Download Source code

Download project by click here

9. References

Comments or suggestions are welcome here to improve this post.


Connect with

59 thoughts on “Hello World JAX-RS Jersey Example with Maven

  1. Now, February 16, important Nigerian newspapers focus on various problems including the secret
    meeting between the presidency and the National Assembly to fix the mistakes in the 2016 budget
    and the sack of the director-general (Budget) Yahaya Gusau.

  2. Wow, that’s what I was looking for, what a stuff!
    present here at this web site, thanks admin of this site.

  3. Hi! I’ve been reading your blog for quite some time now and lastly got the courage to go ahead and offer you a shout from Houston Texas! Just wanted to mention keep up to date the good job!

  4. Hello just wanted to provide a simple heads up.The words in your content seem to be running away from the
    screen in Internet explorer. I’m not sure if this is a formatting issue or something connected to internet
    browser compatibility having said that i figured I’d post to inform you. The design and design look fantastic though! Hope you obtain the issue fixed soon. Thanks

  5. Thanks for a marvelous posting! I genuinely enjoyed reading it, you happen to be an incredible author. I will ensure that you bookmark your website and may eventually return inside the near future. I wish to encourage a person to continue your great work, have a nice holiday weekend!

  6. Wonderful blog! I discovered it while browsing on Yahoo News. Have you got any tips concerning how to get listed in Yahoo News? I’ve been trying for a while but I never manage to arrive! Appreciate it

  7. Hi, i read your website occasionally and i also own a similar one
    and i also was only wondering if you achieve a great deal

  8. I used to be extremely pleased to discover this page. I need to to thanks for ones time only for this fantastic read!!

    I definitely enjoyed every small amount of it and i also have you ever bookmarked
    to consider new things on the website.

  9. Hi there, just became aware about your blog site through Google,
    and located that it can be truly informative. I’m gonna be aware of brussels.
    I’ll be grateful in the event you continue this later on. Many men and women will be took advantage of your writing.
    Cheers!

  10. What’s Happening i’m a novice to this, I discovered this
    I’ve discovered It positively useful and contains aided me out loads.
    I’m hoping to provide a contribution & aid different customers like its aided me.
    Great job.

  11. I’m really impressed along with your writing skills and also with the layout
    on your own weblog. Is that this a paid theme or would you modify it yourself?
    In any case maintain the excellent quality writing, it can be rare to view a
    great blog such as this one currently.

  12. Wow! This web site looks exactly like my old one!
    It’s with a entirely different subject nevertheless
    it has virtually a similar page layout and design. Superb range of colors!

  13. Thanks for the auspicious writeup. It in truth used to be a entertainment account it.
    Look advanced to more brought agreeable from you! However, how can we communicate?

  14. Hello! I’m at work surfing around your blog from my new iphone 4!
    Just wanted to say I love reading your blog and look forward to all your posts!
    Keep up the excellent work!

  15. It’s a pity you don’t have a donate button! I’d definitely donate to this particular outstanding blog!
    I guess for now i’ll be satisfied with book-marking and adding your
    Feed to my Google account. I look forward to brand-new updates and may share this website with my Facebook group.

    Chat soon!

  16. I will not even know how I wound up here, but I thought this post was good.
    I don’t know what you are about but certainly you’re seeing a famous blogger should you aren’t already
    😉 Cheers!

  17. We’re a gaggle of volunteers and opening a completely
    new scheme in your community. Your website provided us with valuable info to work on. You’ve done a formidable job and our whole neighborhood is going to be thankful for you.

  18. Magnificent website. Plenty of useful information here.
    I am sending it to some buddies ans additionally sharing in delicious.
    And obviously, thanks for the effort!

  19. Im not too a good deal of internet reader actually yet your sites very
    nice, keep it up! I’ll just bookmark your website to come back down the
    line. Cheers

  20. Hi all, here every person is sharing these kinds of know-how, so
    it’s nice to read this webpage, and I used to visit
    this webpage every day.

  21. You are so awesome! I do not think I’ve read through one particular thing
    such as that before. So good to find somebody with just a few original thoughts on this issue.
    Really.. thanks for starting this up. This web site is something that is needed on the web, someone
    with a bit of originality!

  22. I love what you guys are usually up too. Such clever work and exposure!
    Keep up the excellent works guys I’ve incorporated you guys to my blogroll.

  23. My relatives constantly point out that I am just killing my time right here
    at net, but I realize I am just getting know-how every
    single day by reading such good content.

  24. Greetings! This is my 1st comment here so I just wanted to give a quick shout out and
    tell you I genuinely enjoy reading through your posts.

  25. I am just regular visitor, how are you currently everybody? This piece of writing posted at the site is actually nice.

  26. continuously i accustomed to read smaller articles or reviews that at the same time clear their motive, and that
    is also happening with this particular post which I am reading at the moment.

  27. I just like the helpful information you supply inside
    your articles. I am going to bookmark your weblog and take a
    look at once more here regularly. I am rather sure I am
    going to be informed many new stuff proper here!
    Best of luck for the next!

  28. Hey There. I stumbled upon your website using msn. This can be an extremely well written article.

    I’ll make certain to bookmark it and return to see a greater portion of your useful information. Thanks for the post.
    I’ll certainly comeback.

  29. My brother recommended I might like this web site.

    He was entirely right. This post truly made my day.
    You can not imagine simply how much time I had spent for
    this information! Thanks!

  30. Tremendous issues here. I’m very happy to see your
    post. Thanks a lot and I am having a look ahead to touch you.
    Will you kindly drop me a e-mail?

  31. Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something.
    I think that you can do with some pics to drive the message home a bit, but other than that, this is
    fantastic blog. A fantastic read. I’ll certainly be back.

  32. Hello there, You’ve done a fantastic job. I will certainly digg it and personally suggest to my friends.
    I am sure they’ll be benefited from this website.

  33. Hi to every , because I am truly keen of reading this website’s post to be updated on a regular
    basis. It consists of nice information.

  34. Do you have a spam problem on this site; I also am a blogger, and I was wanting to know your situation; many of us have created
    some nice practices and we are looking to swap techniques with other folks, be
    sure to shoot me an e-mail if interested.

  35. Hmm it appears just like your site ate my first comment (it was extremely
    long) thus i guess I’ll just sum it up the things i wrote and say,
    I’m thoroughly enjoying your blog site. I too am an aspiring blog blogger but I’m still
    a new comer to everything. Do you have any helpful hints for inexperienced blog
    writers? I’d definitely appreciate it.

  36. I tend not to have any idea the way i finished up
    here, however i thought this post was good. I will not know your identiity but definitely you’re seeing a famous blogger if you are certainly not
    already 😉 Cheers!

Leave a Reply

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