• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cant Run Simple Jersey REST Webservice Example

 
Ranch Hand
Posts: 230
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I am trying to run a very simple example from http://www.ibm.com/developerworks/web/library/wa-aj-tomcat/#download of building a REST Jersey Webservice
Here is what i did
-Named the project Jersey (Dynamic Web Project)
-Created a package "sample.hello.resources"
-Added a class called "HelloResource"
-The code of the class HelloResource is



-Changed the web.xml file to the following


-I then added the project to my server (TOMCAT in eclipse)
-I then typed the followoing url http://localhost:8080/Jersey/rest/hello
And i get the following message
 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any idea why i am getting "404-Service not available" in Firefox
 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I finally managed o solve the problem. Just needed to dump the rar libraries in the correct folder.
 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

I have the same the problem (the only difference is that I am using sailfin instead of tomcat).
What rars did you copy and where ?


Thanks
 
Rajesh Khan
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All the rar files in the lib folder of Jersey in the containers folder.
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just now ran into this problem while following the Jersey docs and finally figured out what the docs failed to mention. For those of you using Maven to build your web app, you need to add the following dependency:



Thus, for the simple hello example at http://jersey.java.net/nonav/documentation/latest/getting-started.html, modifying it to run as a web app as mentioned at http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e188, you only need 2 dependencies: jersey-server and jersey-servlet (this assumes that in your webapp you won't have the Main class that used grizzly to run the web service).

Your resulting WAR file should have the following JARS:

WEB-INF/lib/asm-3.1.jar
WEB-INF/lib/jersey-core-1.12.jar
WEB-INF/lib/jersey-server-1.12.jar
WEB-INF/lib/jersey-servlet-1.12.jar
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Check if jersey-server library is there in the Path.
Sometimes, if your version doesn't match, then there's problem in jersey server startup.
I too faced the problem. Later with jersey-server-1.9.1.rar, the problem got solved.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the same problem.

"What rars did you copy and where ?" - please be more specific because I am newer (Web Services, servlet, and Eclipse).

I put the jar libraries (not rar) in the lib folder of the "Jersy" project (see attachment).

When I type " http://localhost:8080/Jersey/rest/hello " URL I still got "NOT-FOUND".

what you meant when saying "All the rar files in the lib folder of Jersey in the containers folder":
- what is the container folder ?.
- I am testing it in the development are (just using jar)



NOT-FOUND-404.png
[Thumbnail for NOT-FOUND-404.png]
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am having the same problem with another tutorial.

I am using Eclipse (STS 3.2), Tomcat 7.0.26, Jersey 1.17, JDK 1.6.

When Tomcat starts up I see the following error message:

Jul 25, 2013 7:53:02 AM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /de.vogella.jersey.first threw load() exception
java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer

The class in question is in jersey-servlet-1.17.jar and all the jersey jars are in the Java Build Path -> Libraries.

Can anyone tell me what the problem is and how to fix it?

Thanks,
Anand
 
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

all the jersey jars are in the Java Build Path -> Libraries.


There's your problem: build path != runtime path. The libraries need to be in the WEB-INF/lib directory of your web app.

This is a typical case where IDEs behave differently than standalone servers. I never run Tomcat in an IDE, it just complicates matters IMO.
 
Anand A. Parikh
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Ulf,

I also copied all the jersey jars to the WEB-INF/lib folder.
I get the same error. What could be the problem?

Thanks,
Anand
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So this is a standalone Tomcat, run independently of Eclipse, the WEB-INF/lib directory of your web app contains a jar file that has the missing class, and still you're getting that exception?
 
Anand A. Parikh
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I should have given more details in the reply.

I am still running Tomcat through Eclipse IDE. I have copied the jersey jars to the WEB-INF/lib folder and to the Java Build Path -> Libraries folder of the web app.
Yet I am getting the exception.
 
Anand A. Parikh
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I exported the web app as a .war file and started Tomcat independently (external to Eclipse IDE).
Now, the example works OK.

There is definitely a problem running Tomcat through Eclipse IDE.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Follow this tutorial to create a simple web service. It worked for me -

http://javacodingtutorial.blogspot.com/2013/10/creating-web-service-with-maven-jersey.html

Thanks,

Srijani
 
reply
    Bookmark Topic Watch Topic
  • New Topic