permaculture playing cards*
The moose likes Web Services and the fly likes Cant Run Simple Jersey REST Webservice Example Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Cant Run Simple Jersey REST Webservice Example" Watch "Cant Run Simple Jersey REST Webservice Example" New topic
Author

Cant Run Simple Jersey REST Webservice Example

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
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

Joined: Oct 16, 2011
Posts: 230
Any idea why i am getting "404-Service not available" in Firefox
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
I finally managed o solve the problem. Just needed to dump the rar libraries in the correct folder.
Rani Amra
Greenhorn

Joined: Mar 18, 2012
Posts: 1

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

Joined: Oct 16, 2011
Posts: 230
All the rar files in the lib folder of Jersey in the containers folder.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5779
    
    7

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

JBoss In Action
capsul das
Greenhorn

Joined: Jan 06, 2009
Posts: 1
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.
David Zweigenhaft
Greenhorn

Joined: Apr 30, 2013
Posts: 1
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)





[Thumbnail for NOT-FOUND 404.png]

Anand A. Parikh
Greenhorn

Joined: May 12, 2009
Posts: 21

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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Anand A. Parikh
Greenhorn

Joined: May 12, 2009
Posts: 21

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
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
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

Joined: May 12, 2009
Posts: 21
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

Joined: May 12, 2009
Posts: 21
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.
Srijani Ghosh
Greenhorn

Joined: Oct 11, 2013
Posts: 2
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cant Run Simple Jersey REST Webservice Example
 
Similar Threads
404 error while trying to test spring3 rest service
struts1
[solved]Struts 2 and Vaadin
Using Vaadin and Struts 1 together
problem in deploying war file