0

I got the following Error in Eclipse:

HTTP Status 500 - Unable to compile class for JSP:

type Exception report

message Unable to compile class for JSP:

description The server encountered an internal error that prevented it from fulfilling this request.

exception org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 1 in the generated java file: [C:\Users[...].metadata.plugins\org.eclipse.wst.server.core\tmp1\work\Catalina\localhost[...]\org\apache\jsp\test[...]_jsp.java] The type com.fasterxml.jackson.core.JsonParseException cannot be resolved. It is indirectly referenced from required .class files

An error occurred at line: [19] in the generated java file: [C:\Users[...].metadata.plugins\org.eclipse.wst.server.core\tmp1\work\Catalina\localhost[...]\org\apache\jsp\test[...]_jsp.java] Only a type can be imported. com.fasterxml.jackson.core.JsonParseException resolves to a package

An error occurred at line: 23 in the jsp file: /test/[...].jsp The method get(String) from the type [...] refers to the missing type JsonParseException

Stacktrace: org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:366) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:468) org.apache.jasper.compiler.Compiler.compile(Compiler.java:378) org.apache.jasper.compiler.Compiler.compile(Compiler.java:353) org.apache.jasper.compiler.Compiler.compile(Compiler.java:340) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.

Normally I understand this means that a class that I use needs another class that is not on the classpath as answered by @Arne here

However the class is in the class path and everything works fine when I run it from a main method in a .java file. But it doesn't work anymore when I run it from a .jsp file on a Tomcat Server. How is this possible?

Code

Both the JSP File and the java main method call the same class Wiki Picture, which basically just uses the Wikipedia API to get the article pictures.

Strangely the main method works while the jsp file on a Tomcat Server throws exceptions.

JSP File

<%@ page import="json.*" %>
<%@ page import="main.*" %>
<%@ page import="java.util.*" %>

<%@ page import="com.fasterxml.jackson.databind.*" %>
<%@ page import="com.fasterxml.jackson.core.*" %>
<%@ page import="com.fasterxml.jackson.core.JsonParseException" %>


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%

ArrayList<WikiPicture> pictures = WikiPicture.get("London");

for (WikiPicture picture: pictures) {
    System.out.println("picture: " + picture.getURL());
}

%>

</body>
</html>

Java main method

package json;

import java.util.ArrayList;

import com.fasterxml.jackson.core.JsonParseException;

public class JsonTest {

    public static void main(String args[]) {

        ArrayList<WikiPicture> pictures = null;;
        try {
            pictures = WikiPicture.get("Lausanne");
        } catch (JsonParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        for (WikiPicture picture: pictures) {
            System.out.println("picture: " + picture.getURL());
        }
    }
}
Community
  • 1
  • 1
sevku
  • 63
  • 1
  • 1
  • 10
  • No idea without any context. – Christopher Schneider Mar 06 '17 at 15:42
  • @Christopherschneider I've update the error message. – sevku Mar 06 '17 at 17:01
  • What I am trying to do is process JSON data with Jackson – sevku Mar 06 '17 at 17:01
  • `An error occurred at line: 1 in the generated java file: ` I'd start by looking at the generated Java file on line 1. You could have a dependency conflict, as well. Verify transitive dependencies aren't overriding a required dependency. – Christopher Schneider Mar 06 '17 at 17:50
  • @CheistopherSchneider is the "generated Java file" the jsp file or something else? Because in the jsp there can not be an error on line 1. – sevku Mar 06 '17 at 18:53
  • Check your import statement on JSP page and also check `jackson jar` is available on classpath. – Naman Mar 07 '17 at 06:23
  • @Naman thank you for your reply. I've added some code. Not sure if I need to add more, it's quite a lot. But I think this should help a little. – sevku Mar 07 '17 at 20:17

1 Answers1

0

Place jackson-core.jar in WEB-INF/lib directory. Your JSP is not able to find the class com.fasterxml.jackson.core.JsonParseException

VHS
  • 9,534
  • 3
  • 19
  • 43
  • Why downvote? What's wrong with it? – VHS Mar 07 '17 at 20:59
  • I wonder why that got downvoted too. It wasn't me. I will try it. Thanks for the answer. – sevku Mar 07 '17 at 21:25
  • It seems like it worked!!! Thank you very much. I hope it actually did, I will test it more and try to implement the program. Thanks again. – sevku Mar 07 '17 at 21:27
  • @sevku, thanks for the confirmation. Please test it out more and make sure it indeed works. If it does, please mark this as the answer so that the future readers are benefited. Looking at this negative vote, readers won't even read it. – VHS Mar 07 '17 at 21:29
  • Yep! Works just like I expected it to work. There is one confusing thing tough. I now have a lib folder in the Java Resources and one in the Web-INF folder. Is it somehow possible to use only one? – sevku Mar 07 '17 at 21:29
  • What do you have in the one under resources? – VHS Mar 07 '17 at 21:30
  • I can confirm it but I can't upvote it anymore as the downvote on my answer put me under the required 15 point. Thanks downvoter. – sevku Mar 07 '17 at 21:31
  • I've basically used that before - so I got everything under that folder. It seemed like it worked before - someone else who worked on it put the mariadb jar into there and it seemed to work. Don't know why I couldn't put the jackson jar there too. You have to excuse, I'm a very beginner. – sevku Mar 07 '17 at 21:32
  • For `Tomcat`, WEB-INF/lib is always on class-path. So you can move that mariadb jar there. It should work as is. If it does, you can get rid of the resource/lib folder. By the way, I wasn't the downvoter on your question. I have just upvoted it. See if it helps. – VHS Mar 07 '17 at 21:36
  • Ok I will try that. Thank for your patience. – sevku Mar 07 '17 at 21:40
  • And yup, your upvote gave me the 5 credits back to upvote your answer. ;) I know it wasn't you. Just a comment about the one who did it. – sevku Mar 07 '17 at 21:40