facebook

[Closed] Only a type can be imported

  1. MyEclipse Archived
  2.  > 
  3. Application Servers and Deployment
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #242899 Reply

    pg33
    Member

    Hello,

    I have created a simple web project with MyEclipse 4.0.3 GA which contents is :

    – a class called “Class” in a package called “com.asmalltest.general”.
    – a test.jsp file :

    importing the class at the beginning of the file

                    <%@ page import="com.asmalltest.general.Class" %>
    

    and using an instance in the body :

                  <body>
                     <%
                           Class anObject = new Class("Property Value");
                         out.println(anObject.getProperty());
                    %>
                 </body>
    

    The deployment on Tomcat 5.5.12 works well, nevertheless, an error occurs when I click in order to display the test.jsp file :

    org.apache.jasper.JasperException: Impossible de compiler la classe pour la JSP

    Erreur de servlet générée:
    Only a type can be imported. com.asmalltest.general.Class resolves to a package

    I have watched some other topics on the forums before writing this one and this seems to be probably quite the same problem as the subject entitled “the import org.apache.log4j can not be resolved”, but in this case the class required is inside the project and not an in an external JAR.

    After some searches on the Internet I found this could come from the CLASSPATH variable but I am not sure about this and I wonder which value to set in in order to make each web project works fine.

    Any advice is welcome,

    Thanks and Regards,

    pg33

    —————————————————–

    Here is my configuration summary :

    *** Date: Fri Dec 09 11:07:39 CET 2005

    *** System properties:
    OS=WindowsXP
    OS version=5.1
    Java version=1.5.0_03

    *** MyEclipse details:
    MyEclipse Enterprise Workbench

    Version: 4.0.3 GA
    Build id: 20051025-4.0.3-GA

    *** Eclipse details:
    Eclipse SDK

    Version: 3.1.1
    Build id: M20050929-0840

    SDK du projet Eclipse

    Version : 3.1.1
    ID compilation : M20050929-0840

    Plateforme Eclipse

    Version : 3.1.1
    ID compilation : M20050929-0840

    Outils de développement Java Eclipse

    Version : 3.1.1
    ID compilation : I20050627-1435

    Eclipse RCP

    Version: 3.1.1
    Build id: I20050627-1435

    Environnement de développement du plug-in Eclipse

    Version: 3.1.1
    ID compilation : I20050627-1435

    Eclipse startup command=-os
    win32
    -ws
    win32
    -arch
    x86
    -launcher
    C:\Program Files\Eclipse 3.1\eclipse\eclipse.exe
    -name
    Eclipse
    -showsplash
    600
    -exitdata
    bc4_4c
    -vm
    C:\jdk1.5.0_03\bin\javaw.exe

    #242909 Reply

    Riyad Kalla
    Member

    pg33,
    Please post the ENTIRE contents of your Class file here, use the “code” button below to wrap it, so the formatting is maintained.

    I have a feeling either your package statement is wrong, or there is a problem caused by you using the name “Class”. It’s typically a good idea not to use well known names for your own class names.

    #242934 Reply

    pg33
    Member

    Hello,

    I agree with you for the advice about the class name so I renamed it “Example” and I retried.

    Here is the complete code of Example.java :

    package com.asmalltest.general;
    
    public class Example {
        
        private String property;
        
        public String getProperty() {
            return property;
        }
    
        public Example(String argProperty) {
            
            this.property = argProperty;
        }
    }
    

    and the complete related error message :

    org.apache.jasper.JasperException: Impossible de compiler la classe pour la JSP
    
    Erreur de servlet générée:
    Only a type can be imported. com.asmalltest.general.Example resolves to a package
    
    Une erreur s'est produite à la ligne: 28 dans le fichier jsp: /WebRoot/test.jsp
    Erreur de servlet générée:
    The constructor Class(String) is undefined
    
    Une erreur s'est produite à la ligne: 28 dans le fichier jsp: /WebRoot/test.jsp
    Erreur de servlet générée:
    The method getProperty() is undefined for the type Class
    
    
        org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
        org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
        org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
        org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    

    The Tomcat error message “<classname> resolves to a package” is, at my point of view, not appropriate for the situation because there is really a class called Example.java in a real package.

    As for system variables :

    CLASSPATH=C:\Oracle\ora92\jdbc\lib\classes12.zip;C:\Oracle\ora92\jdbc\lib\nls_charset12.zip
    (info added by the installation of a version of Oracle coming from a disk delivered with a SQL/Oracle book)
    JAVA_HOME=C:\jdk1.5.0_03
    CATALINA_HOME=C:\Program Files\Apache Software Foundation\Tomcat 5.5

    I should also add that my web projects used to work until late October, when I updated Tomcat (5.0 before) and MyEclipse. That is why I created a simple web project to test the problem.

    pg

    #242938 Reply

    pg33
    Member

    Sorry, I forgot to change the test.jsp use of “Example” instead of “Class”.

    Here is the entire code of test.jsp :

    
    
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ page import="com.asmalltest.general.Example" %>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'test.jsp' starting page</title>
        
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="This is my page">
        
        <!--
        <link rel="stylesheet" type="text/css" href="styles.css">
        -->
      </head>
      
      <body>
        <%
            Example anObject = new Example("Property Value");
            out.println(anObject.getProperty());
        %>
      </body>
    </html>
    

    and the entire error message displayed in Tomcat (this time with Example) :

    org.apache.jasper.JasperException: Impossible de compiler la classe pour la JSP
    
    Erreur de servlet générée:
    Only a type can be imported. com.asmalltest.general.Example resolves to a package
    
    Une erreur s'est produite à la ligne: 28 dans le fichier jsp: /WebRoot/test.jsp
    Erreur de servlet générée:
    Example cannot be resolved to a type
    
    Une erreur s'est produite à la ligne: 28 dans le fichier jsp: /WebRoot/test.jsp
    Erreur de servlet générée:
    Example cannot be resolved to a type
    
    
        org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
        org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
        org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:409)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
        org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    #242949 Reply

    Riyad Kalla
    Member

    This baffles me, can you send me this project?

    File > Export > ZIP, email it to support@genuitec.com ATTN Riyad, and provide a link to this post so I know why I’m getting it please.

    #242970 Reply

    Riyad Kalla
    Member

    I got your project, imported it and rebuilt it, nothing was wrong at all. No error markers, autocomplete worked fine, everything is a-ok. This makes me think something is going on with your JDK setup.

    When the error marker pops up on your side, is it in the left margin or right margin?

    #243088 Reply

    pg33
    Member

    Hello,

    First sorry for my late answer, I forgot to check the notification checkbox in my last reply so I saw your message only yesterday.

    I finally uninstalled MyEclipse (3.8.4, 4.0, 4.0.3), Eclipse 3.1.1, Eclipse 3.0, Tomcat and reinstalled Eclipse 3.1.1, MyEclipse 4.0.3 and Tomcat 5.5.12 from scratch. Instead of waiting 5 minutes to run Eclipse, now the delay is only 15 seconds. Maybe there were too much unused plug-ins in my previous configuration…

    I retried the Test project and it works. I tried for a while to find what was wrong before and I noticed that when the application is deployed from MyEclipse it works, but when it is deployed from Tomcat the error “Only a type can be imported” occurs. I think that I have to learn a lot about J2EE development and application servers.

    Thank you for your time, this topic can be closed.

    #243092 Reply

    Riyad Kalla
    Member

    Thank you for doing that pg33 and glad to hear things are working as they should now.

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: [Closed] Only a type can be imported

You must be logged in to post in the forum log in