aspose file tools*
The moose likes JSP and the fly likes cannot resolve symbol error when a class is imported from another project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "cannot resolve symbol error when a class is imported from another project" Watch "cannot resolve symbol error when a class is imported from another project" New topic
Author

cannot resolve symbol error when a class is imported from another project

geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
I have created a Web Project. I already have a simple java project, that has a public class A.

I have included this java project in the classpath of this web project. In the welcome jsp of this project, i have imported this class through the page directive and then in the scriptlet i create an instance of this class.

When i execute the application, i get cannot resolve symbol A. What could be the problem?
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Can you post your JSP and error message here?
geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
This is the jsp:



The error messsage:

test_project.war\_test1.java:4: '.' expected import A; ^ An error occurred between lines: 22 and 27 in the jsp file: /test1.jsp Generated servlet error:

cannot resolve symbol symbol : class A location: class org.apache.jsp._test1 A ab = new A(); ^ An error occurred between lines: 22 and 27 in the jsp file: /test1.jsp Generated servlet error:

test_project.war\_test1.java:78: cannot resolve symbol symbol : class A location: class org.apache.jsp._test1 A ab = new A(); ^ 3 errors



Note: Class A is just a empty class in the simple java project.There are no compilation errors, and this is the runtime error.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Put class A in a package and correctly import the package into the JSP.
When classes dont have an explicit package the JVM looks in the "current" directory - something you have no control over in the servlet/jsp environment.
ALL classes used in servlets/jsp should be in packages to avoid hard to understand bugs.
Bill
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This is a very common question here so we've written a FAQ entry for it.
See:
http://faq.javaranch.com/view?BeansNotFound
and
http://faq.javaranch.com/view?PackageYourBeans


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
I had tested putting Class A in a package 'tutorial.databeans'(in the simple java project). And i get the same error.

What i noticed is that the class in the default package appears in the WEB-INF/classes folder of the web project, whereas i could not find the class in the package. Why could this be?
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by geetu lalchandani:
I had tested putting Class A in a package 'tutorial.databeans'(in the simple java project). And i get the same error.

What i noticed is that the class in the default package appears in the WEB-INF/classes folder of the web project, whereas i could not find the class in the package. Why could this be?


Did you compile your class?
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
and did you change the following:

<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="tutorial.databeans.A"
%>


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Please send the directory structure where your class file resides.
geeta lalchandani
Ranch Hand

Joined: Jun 07, 2005
Posts: 118
yes , i have done both. Compiled the class and well as changed the import as.
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="tutorial.databeans.A"
%>
 
Consider Paul's rocket mass heater.
 
subject: cannot resolve symbol error when a class is imported from another project