Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException with eclipse and spring

I have a simple XML file that I have parsed to JSON. All is fine and dandy, I have a Java class that is stand alone (i.e. it has a public static void main (String args[])....)

This has a private constructor (because I need to call it with Strings either a filename or the actual data). So I have two methods that return an instance of the object. I know a bit of Java as you can tell.

OK. When I run the code in Eclipse that runs the main method my file is loaded and decoded as required. It also works for a raw String that I run via JUnit.

So I know the following facts -

  1. the parsing of a static String works and decodes perfectly
  2. if I provide a file it is loaded and decoded correctly.

Now the issue:

As soon as I run it in Spring framework I can write to standard out the entire file content that I have run via the stand alone code.

But before it can run anything at all I get the below error -

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:920)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

The stand alone code is run in Eclipse, and the Spring is run pointing to that code using Tomcat 7.

Why is it not finding the ParsException correctly?

The imports in the calling Spring controller are

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import org.apache.commons.lang.StringUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

Is their a way of altering the build order, and would that fix it?

like image 742
Roger Stark Avatar asked Feb 02 '13 01:02

Roger Stark


2 Answers

Looks like you have missed including the json-simple-.jar in your classpath. Include the same and it should get solved.

Hope this helps !

like image 168
Anugoonj Avatar answered Oct 18 '22 22:10

Anugoonj


  1. Add json-simple-1.1.1.jar file in your build path. On Eclipse, right click on project-> build path -> configure build path -> java build path -> add external jars -> select the jar file.

  2. Add build path entry into deployment assembly. On the same properties window, Select "deployment assembly" option. Then add "Java Build Path" entries. This should show you the build path entry you just made in step one.

like image 39
Gyanesh Sharma Avatar answered Oct 19 '22 00:10

Gyanesh Sharma