Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't access class files

Status
Not open for further replies.

lochem

Programmer
Aug 11, 2005
7
PL
Hi!
I use Tomcat 5.5 on WinXp HomeEd.
I cannot use my .class files in my jsp pages.
I tried several locations for the .class files:
{TomcatHome}\shared\classes\
and
{TomcatHome}\webapps\ROOT\MyApplication\WEB-INF\classes\
and
{TomcatHome}\common\classes\
and
{TomcatHome}\server\classes\
and nothing works!
What should I do to make my .class files visible to the server?
hoping for answer.....

 
This directory seems a bit weird :

{TomcatHome}\webapps\ROOT\MyApplication\WEB-INF\classes\


Do you not mean :

{TomcatHome}\webapps\MyApplication\WEB-INF\classes\ ?

In any case, the best practice is to jar up your classes, and put them in your webapp's WEB-INF/lib directory, or if common to many webapps, in TOMCAT_HOME/common/lib .

Seeing as you do not actually provide any errors, or whether the classes are in packages or not etc, there is not a lot else I can offer.


--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hi!
Tnx sedj for your reply.
Let me give some more details.
I want to use my class called TBean in my jsp page called t.jsp.
This class is not packed (is not a .jar file)
I get this error:

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

An error occurred at line: 13 in the jsp file: /cos/t.jsp
Generated servlet error:
TBean cannot be resolved or is not a type

An error occurred at line: 13 in the jsp file: /cos/t.jsp
Generated servlet error:
TBean cannot be resolved or is not 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:397)
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:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

And I put the TBean.class in directories mentioned in my first message.
What's wrong?
 
You cannot use non-packaged classes.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I should probably be clearer :

Your class should be in a package, eg :

package com.acme;
class TBean {

}

Its best to archive them into a jar file too, but this is optional.

If you must use them as un-jarred, you should put them in :

TOMCAT_HOME/webapps/YOUR_WEBAPP/WEB-INF/classes/com/acme

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Still have a problem.
I defined my TBean like this:

package com.cos;
public class TBean {

}

I compiled it to TBean.class

Then I put TBean.class to TOMCAT_HOME/webapps/MY_WEBAPP/WEB-INF/classes/com/cos

and in my jsp page I have
<%@ page language="java" contentType="text/html; charSet=UTF-8" import="com.cos.TBean"%>

and I get this error:

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

Generated servlet error:
Only a type can be imported. com.cos.TBean resolves to a package

An error occurred at line: 13 in the jsp file: /myapp/t.jsp
Generated servlet error:
TBean cannot be resolved or is not a type

An error occurred at line: 13 in the jsp file: /myapp/t.jsp
Generated servlet error:
TBean cannot be resolved or is not 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:397)
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:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

what's that now?

 
Forget this :

<%@ page language="java" contentType="text/html; charSet=UTF-8" import="com.cos.TBean"%>

Use this :

<%@ page import="com.cos.*" %>

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I put <%@ page import="com.cos.*" %> as you advised
but it doesn't work
I get this error:

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

An error occurred at line: 14 in the jsp file: /myapp/t.jsp
Generated servlet error:
TBean cannot be resolved or is not a type

An error occurred at line: 14 in the jsp file: /myapp/t.jsp
Generated servlet error:
TBean cannot be resolved or is not 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:397)
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:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

What else can I do?
 
Have you compiled your com.cos.TBean class correctly ?

The package must be in the correct directory structure.
So if you were compiling it from "/usr/java", your class should be in :

/usr
/java
/com
/cos

and you would compile it so :

From /usr/java :

javac com/cos/TBean.java

This is all standard Java package stuff, and you should know all this before attemping to use any non-standard APIs ....

Your class when in Tomcat should also be in the correct directory, eg :

WEB-INF/classes/com/cos

And I really would jar it all up - it really is best practice.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Finally!!!
I have solved my problem.
Sedj, you have been very helpful.
I wouldn't do it without your hints.
Thanks again.
Bye!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top