Reputation: 163
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 -
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?
Upvotes: 7
Views: 54603
Reputation: 314
Just add maven dependency of JSON simple in your pom.xml. No need to configure any classpath.
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
Upvotes: 0
Reputation: 11580
Use the below java library for process JSONArray and JSONObject
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20200518</version>
</dependency>
Upvotes: 0
Reputation: 1
IF you are making an AI in Spring as I was when I had this error:
You also need to add the Jar to your AI "jlib" folder, for instance "...\AI\Skirmish\MyAI\0.1\jlib".
It's not enough to add it in Eclipse or Netbeans and build the project. Spring must have the jar too.
I know it is a late answer it but can help other people with the same error.
Upvotes: 0
Reputation: 76
I have had a similar error and spent 3 4 hours removing and adding new jar files. What my problem was that i added jar file directly from the download location ie THE ZIP files ..!!! after adding a proper extracted jar file , My problem seems to be resolved. Hope this helps someone..!!
Upvotes: 0
Reputation: 481
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.
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.
Upvotes: 7
Reputation: 163
The solution that I used in the end was to change to sourceforge.net json parser, a couple of code tweaks and my JUnit tests still worked and Tomcat did not complain. This may not be the best solution but it worked.
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
Upvotes: 0
Reputation: 575
Looks like you have missed including the json-simple-.jar in your classpath. Include the same and it should get solved.
Hope this helps !
Upvotes: 8
Reputation: 397
Could you please add this jar json-simple-1.1.1.jar in your classpath and try it out ? This jar can be downloaded at http://code.google.com/p/json-simple/downloads/detail?name=json-simple-1.1.1.jar
Upvotes: 1
Reputation:
you are missing a jar deployment.
it is related for Tomcat7. A few jar needed to be exported ( forgot which ones) other web server doesn't need but Tomcat.
Upvotes: 0