Matthieu Le Scornet Matthieu Le Scornet - 4 months ago 47
Java Question

Unable to compile class for JSP, import cannot be resolved

I'll post my first question on this forum so be kindly =)

My problem is that my import on my jsp file cannot be resolved :

<%@ page import="java.util.List" %>
<%@ page import="com.javapapers.java.social.facebook.FBConnection" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%
FBConnection fbConnection = new FBConnection();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Java Facebook Login</title>
</head>
<body style="text-align: center; margin: 0 auto;">
<div
style="margin: 0 auto; background-image: url(./img/fbloginbckgrnd.jpg); height: 360px; width: 610px;">
<a href="<%=fbConnection.getFBAuthUrl()%>"><img
style="margin-top: 138px;" src="./img/facebookloginbutton.png" />
</a>
</div>
</body>
</html>


I crawled this forum since a day and I've done all what is said and I didn't found the solution for my problem...

here is the error :

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

An error occurred at line: [15] in the generated java file: [C:\Users\Matthieu\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\Facebook_Login\org\apache\jsp\index_jsp.java]
The import com.javapapers.java.social.facebook.FBConnection cannot be resolved

An error occurred at line: 6 in the jsp file: /index.jsp
FBConnection cannot be resolved to a type
3: <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
4: pageEncoding="ISO-8859-1"%>
5: <%
6: FBConnection fbConnection = new FBConnection();
7: %>
8: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
9: <html>


An error occurred at line: 6 in the jsp file: /index.jsp
FBConnection cannot be resolved to a type
3: <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
4: pageEncoding="ISO-8859-1"%>
5: <%
6: FBConnection fbConnection = new FBConnection();
7: %>
8: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
9: <html>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:198)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:450)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


I've put my classes on WEB-INF/classes as recommended (respecting the package name : com/javapapers/java/social/facebook)

I'm working on Eclipse Luna with a TomCat 8.0 server

Deployement assembly :
Deployement Assembly

Librairies :
Librairies

Sources :
Test/src

But the error's still there

Can you help me please

Thanks

Answer

As mentioned above, be sure the .jar file is in your classpath.

Second option is that your deployment does not correspond to what you want.

Check your Eclipse configuration for the Deployment Assembly:

  • right click on your project
  • select Deployment Assembly

If you're working on an external deployment (as opposed to workspace resources), check the resources at the deployment.

Comments