Tomcat with Rest - HTTP Status 500 - Servlet execution threw an exception


I'm trying to code a very simple restful webservice, following some tutorials. I'm searched everywhere but I can't find a solution after several tries that would fit my problem. I'm using Netbeans 8.0.2 and Apache Tomcat 8.0.15 (installed with netbeans). I've had several issues with Tomcat but I managed to solve them, except for this one.


package com.example; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; //Path: http://localhost/<appln-folder-name>/hello @Path("/hello") public class HelloWorld { // HTTP Get Method @GET // Path: http://localhost/<appln-folder-name>/hello/world @Path("/world") // Produces JSON as response @Produces(MediaType.APPLICATION_JSON) public String doHello(){ JSONObject obj = new JSONObject(); try { obj.put("hello", "world"); } catch (JSONException e) { // TODO Auto-generated catch block } System.out.println(obj.toString()); return obj.toString(); } }


<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>restful_example</display-name> <!-->project name<--> <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.example</param-value> <!-->package name<--> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>

The error

<img alt="Here" class="b-lazy" data-src="https://i.imgur.com/fdVXBYs.png" data-original="https://i.imgur.com/fdVXBYs.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" />

To test my service, I followed this: <a href="https://netbeans.org/kb/docs/websvc/rest.html#test-rest" rel="nofollow">https://netbeans.org/kb/docs/websvc/rest.html#test-rest</a>

What am I doing wrong?


You have a jar conflicts problem. Review all your libs. Maybe you are using some jars from different Jersey versiosn


  • Error in inserting a string parameter to a cypher query in a java code
  • Spring Security Login issue
  • Skipping certain files/classes when using asdoc
  • Select value from xtype selection type checkbox CQ5
  • Javascript CORS - No 'Access-Control-Allow-Origin' header is present
  • Exception creating JSON with LINQ
  • Angular2 Response for preflight is invalid (redirect) from some GET requests
  • chrome.tabs.executeScript only fires when the Developer Console is open
  • Play WS (2.2.1): post/put large request
  • Paperclip, set path outside of rails root folder
  • Different response to non-authenticated users and AJAX calls
  • Trying to switch camera back to front but getting exception
  • Akka Routing: Reply's send to router ends up as dead letters
  • Warning: Can't call setState (or forceUpdate) on an unmounted component
  • bootstrap to use multiple ng-app
  • Cannot Parse HTML Data Using Android / JSOUP
  • How to get icons for entities from eclipse?
  • Proper folder structure for lots of source files
  • Load html files in TinyMce
  • Free memory of cv::Mat loaded using FileStorage API
  • JTable with a ScrollPane misbehaving
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Turn off referential integrity in Derby? is it possible?
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Is it possible to post an object from jquery to bottle.py?
  • unknown Exception android
  • Append folder name and increment by 1 using batch script
  • JaxB to read class hierarchy
  • Programmatically clearing map cache
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • failed to connect to specific WiFi in android programmatically
  • UserPrincipal.Current returns apppool on IIS
  • Unable to use reactive element in my shiny app
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal
  • How can I use threading to 'tick' a timer to be accessed by other threads?