2

I'm trying to write a very simple servlet which must extract data from a csv file and display the result, here is the code:

      Reader reader = new FileReader(filePath);
      CSVReader csvReader = new CSVReader(reader);
      String[] data;
      PrintWriter out = response.getWriter();

      response.setContentType("text/html");
      while((data = csvReader.readNext()) != null){
        //do something
      }

but then I receive this log:

Type Exception Report

Message Servlet execution threw an exception

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

javax.servlet.ServletException: Servlet execution threw an exception org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Root Cause

java.lang.NoClassDefFoundError: org/apache/commons/lang3/ObjectUtils com.opencsv.CSVParser.(CSVParser.java:209) com.opencsv.CSVReader.(CSVReader.java:196) com.opencsv.CSVReader.(CSVReader.java:178) com.opencsv.CSVReader.(CSVReader.java:130) com.opencsv.CSVReader.(CSVReader.java:70) TheClass.doGet(TheClass.java:19) javax.servlet.http.HttpServlet.service(HttpServlet.java:634) javax.servlet.http.HttpServlet.service(HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)

Note

The full stack trace of the root cause is available in the server logs.

I'set the tomcat-websocket CLASSPATH and copied the jar file in lib directory in WEB-INF but non of them affected. The problem is raised when we make a CSVReader class. Is there anyone for some helps?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Someone
  • 163
  • 1
  • 3
  • 13
  • Don't post pictures of text here. Post the text. You need the JAR file that contains the missing class mentioned in the exception. No mystery. – user207421 Feb 07 '18 at 23:20
  • as i mentioned, i have the jar file already. nothing changed... – Someone Feb 07 '18 at 23:22

1 Answers1

2

You are saying you have the jar file for opencsv but do you have the jar files for the dependencies? Opencsv has dependencies on two to three apache commons libraries depending on which version of opencsv you are using. The dependencies of the latest version can be found at http://opencsv.sourceforge.net/dependencies.html.

If you are building your project using maven or gradle you should have these dependencies already included in your war file. How are you building/deploying your app?

Scott Conway
  • 975
  • 7
  • 13
  • yes, i have the dependencies. and specially in this case that it doesn't find the ObjectUtils class, i checked the proper jar file is present and the classpath is set either. – Someone Feb 08 '18 at 18:50