Я создаю проект Java EE для класса и пытаюсь использовать пакет Google Gson для отправки JSON в другую часть моего проекта внутри сервлета. Когда я посещаю URL, сопоставленный с вышеупомянутым сервлетом, я ожидаю увидеть необработанный JSON, однако я получаю ClassNotFoundException
.
import com.google.gson.Gson;
import edu.neumont.writingCenter.json.Event;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@WebServlet("/user/appointments/json")
public class UserAppointmentsJsonServlet extends HttpServlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("application/json");
PrintWriter out = response.getWriter();
List<Event> events = new ArrayList<Event>();
for (int i =0; i < 10; i++) {
Event event = new Event();
event.setId(i);
event.setTitle("Test " + i);
event.setAllDay(false);
event.setStart(new Date());
event.setEnd(new Date());
events.add(event);
}
Gson gson = new Gson();
out.print(gson.toJson(events));
out.flush();
}
}
java.lang.NoClassDefFoundError: com / google / gson / Gson at
edu.neumont.writingCenter.servlets.user.appointments.UserAppointmentsJsonServlet.doGet (UserAppointmentsJsonServlet.java:35)
в javax.servlet.http.HttpServlet.service (HttpServlet.java:734) в
javax.servlet.http.HttpServlet.service (HttpServlet.java:847) в
org.apache.catalina.core.StandardWrapper.service (StandardWrapper.java:1539)
в
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:343)
в
org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:217)
в
edu.neumont.writingCenter.filters.SetRootFilter.doFilter (SetRootFilter.java:43)
в
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter (ApplicationFilterChain.java:256)
в
org.apache.catalina.core.ApplicationFilterChain.doFilter (ApplicationFilterChain.java:217)
в
org.apache.catalina.core.StandardWrapperValve.invoke (StandardWrapperValve.java:279)
в
org.apache.catalina.core.StandardContextValve.invoke (StandardContextValve.java:175)
в
org.apache.catalina.core.StandardPipeline.doInvoke (StandardPipeline.java:655)
в
org.apache.catalina.core.StandardPipeline.invoke (StandardPipeline.java:595)
на com.sun.enterprise.web.WebPipeline.invoke (WebPipeline.java:98) на
com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke (PESessionLockingStandardPipeline.java:91)
в
org.apache.catalina.core.StandardHostValve.invoke (StandardHostValve.java:162)
в
org.apache.catalina.connector.CoyoteAdapter.doService (CoyoteAdapter.java:330)
в
org.apache.catalina.connector.CoyoteAdapter.service (CoyoteAdapter.java:231)
в
com.sun.enterprise.v3.services.impl.ContainerMapper.service (ContainerMapper.java:174)
в
com.sun.grizzly.http.ProcessorTask.invokeAdapter (ProcessorTask.java:828)
в
com.sun.grizzly.http.ProcessorTask.doProcess (ProcessorTask.java:725)
в
com.sun.grizzly.http.ProcessorTask.process (ProcessorTask.java:1019)
в
com.sun.grizzly.http.DefaultProtocolFilter.execute (DefaultProtocolFilter.java:225)
в
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter (DefaultProtocolChain.java:137)
в
com.sun.grizzly.DefaultProtocolChain.execute (DefaultProtocolChain.java:104)
в
com.sun.grizzly.DefaultProtocolChain.execute (DefaultProtocolChain.java:90)
в
com.sun.grizzly.http.HttpProtocolChain.execute (HttpProtocolChain.java:79)
в
com.sun.grizzly.ProtocolChainContextTask.doCall (ProtocolChainContextTask.java:54)
в
com.sun.grizzly.SelectionKeyContextTask.call (SelectionKeyContextTask.java:59)
в com.sun.grizzly.ContextTask.run (ContextTask.java:71) в
com.sun.grizzly.util.AbstractThreadPool $ Worker.doWork (AbstractThreadPool.java:532)
в
com.sun.grizzly.util.AbstractThreadPool $ Worker.run (AbstractThreadPool.java:513)
at java.lang.Thread.run (Thread.java:662) Вызывается:
java.lang.ClassNotFoundException: com.google.gson.Gson в
org.glassfish.web.loader.WebappClassLoader.loadClass (WebappClassLoader.java:1519)
в
org.glassfish.web.loader.WebappClassLoader.loadClass (WebappClassLoader.java:1369)
... еще 33