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());
}
}
}