title: Jersey web service gives javax.servlet.ServletException:
body: <p>OK I have a problem with my web service.</p>
  
  <p>I am trying to make an API for a user but after I have deployed the app and try to GET all users it gives me an exception.</p>
  
  <p>Here is my api class: </p>
  
  <pre><code>package api;
  
  
  import java.util.ArrayList;
  
  import javax.ws.rs.Consumes;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  
  import model.UserManager;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import dto.User;
  
  @Path("/user")
  public class UserAPI {
  
      @POST 
      @Path("create-user/{user}")
      @Consumes(MediaType.APPLICATION_JSON)
      @Produces(MediaType.APPLICATION_JSON)
      public Response saveUser(@PathParam("user") User user) throws JSONException {
          UserManager userManager = new UserManager();
          userManager.createUser(user);
  
          return Response.status(200).build();    
      }
  
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public JSONObject getAllUsers() throws JSONException {
          JSONObject users = null;
          try {
              ArrayList&lt;User&gt; usersList = null;
              UserManager userManager = new UserManager();
              usersList = userManager.getUsers();
              JSONObject usersObject = new JSONObject();
              for(int i = 0; i &lt; usersList.size(); i++) {
                  usersObject.put("users", usersList);
              }
              users = usersObject;
          } catch(Exception e) {
              e.printStackTrace();
          }
          return users;   
      }
  
      @POST 
      @Path("edit-user/{id}")
      @Consumes(MediaType.APPLICATION_JSON)
      @Produces(MediaType.APPLICATION_JSON)
      public Response editUser(@PathParam("id") int id) throws JSONException {
          UserManager userManager = new UserManager();
          userManager.editUser(id);
  
          return Response.status(200).build();    
      }
  
      @POST 
      @Path("delete-user/{id}")
      @Consumes(MediaType.APPLICATION_JSON)
      @Produces(MediaType.APPLICATION_JSON)
      public Response deleteUser(@PathParam("id") int id) throws JSONException {
          UserManager userManager = new UserManager();
          userManager.deleteUser(id);
  
          return Response.status(200).build();    
      }
  
      @POST 
      @Path("user-login/{user}")
      @Consumes(MediaType.APPLICATION_JSON)
      @Produces(MediaType.APPLICATION_JSON)
      public Response userLogin(@PathParam("user") User user) throws JSONException {
          UserManager userManager = new UserManager();
          userManager.userLogin(user);
  
          return Response.status(200).build();    
      }
  }
  </code></pre>
  
  <p>Here is the error log:</p>
  
  <pre><code>javax.servlet.ServletException: Servlet.init() for servlet Jersey REST Service threw exception
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:745)
  
  com.sun.jersey.spi.inject.Errors$ErrorMessagesException
      com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
      com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
      com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
      com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
      com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:790)
      com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:491)
      com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:321)
      com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
      com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207)
      com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:376)
      com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:559)
      javax.servlet.GenericServlet.init(GenericServlet.java:158)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:683)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
      org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:745)
  </code></pre>