Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java error: Only a type can be imported. XYZ resolves to a package

I get the error: "Only a type can be imported. XYZ resolves to a package."

Someone has explained the cause here but I am not sure what I supposed to do to fix this. FYI: I am using Eclipse. I have added the code that does the importing below. The java.util.* import works fine.

 <%@ page import="java.util.*"%>  <%@ page import="org.eresearch.knowledgeportal.model.Category"%>  <%@ page import="org.eresearch.knowledgeportal.dao.CategoryDao"%>   <%    CategoryDao catDao = new CategoryDao();   ArrayList<Category> catList = catDao.selectCategory();   //  %> 

Edit: the actual error is below:

 org.apache.jasper.JasperException: Unable to compile class for JSP:    An error occurred at line: 7 in the generated java file  Only a type can be imported. org.eresearch.knowledgeportal.model.Category resolves to a package 
like image 321
Ankur Avatar asked Dec 07 '09 07:12

Ankur


2 Answers

Well, you are not really providing enough details on your webapp but my guess is that you have a JSP with something like that:

<%@ page import="java.util.*,x.y.Z"%>  

And x.y.Z can't be found on the classpath (i.e. is not present under WEB-INF/classes nor in a JAR of WEB-INF/lib).

Double check that the WAR you deploy on Tomcat has the following structure:

my-webapp |-- META-INF |   `-- MANIFEST.MF |-- WEB-INF |   |-- classes |   |   |-- x |   |   |   `-- y |   |   |       `-- Z.class |   |   `-- another |   |       `-- packagename |   |           `-- AnotherClass.class |   |-- lib |   |   |-- ajar.jar |   |   |-- bjar.jar |   |   `-- zjar.jar |   `-- web.xml |-- a.jsp |-- b.jsp `-- index.jsp 

Or that the JAR that bundles x.y.Z.class is present under WEB-INF/lib.

like image 151
Pascal Thivent Avatar answered Sep 21 '22 11:09

Pascal Thivent


OK I just solved it. In the last import I added a ";" by copying other code examples. I guess it's the standard line ending that is required.

So

<%@ page import="java.util.*" %> <%@ page import="org.eresearch.knowledgeportal.dao.CategoryDao" %> <%@ page import="org.eresearch.knowledgeportal.model.Category" %> 

became

 <%@ page import="java.util.*" %>  <%@ page import="org.eresearch.knowledgeportal.dao.CategoryDao" %>  <%@ page import="org.eresearch.knowledgeportal.model.Category;" %> 
like image 31
Ankur Avatar answered Sep 19 '22 11:09

Ankur