File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Changing ClassPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Changing ClassPath" Watch "Changing ClassPath" New topic

Changing ClassPath

George Larry
Ranch Hand

Joined: Nov 07, 2001
Posts: 52
How can I append to/change my ClassPath? I can't get any of my beans to work with Tomcat 4. I've copied them into every tomcat directory... just to expirement- though I knew it wouldn't help. I thought that I just had to place them in either the WEB-INF/classes or <TOMCAT_HOME>/classes directory.
I think that the problem is that when I start Tomcat it gives me this:
Using CATALINA_BASE: C:\Tomcat
Using CATALINA_HOME: C:\Tomcat
Using CLASSPATH: C:\Tomcat\bin\bootstrap.jar;C:\jdk\lib\tools.jar
Using JAVA_HOME C:\jdk
I need to add my class directory to that classpath... methinks. Am I right? If I am- How can I do that. If I'm wrong... what might be my problem?
Thank you kindly.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
When you put the bean class files in the WEB-INF/classes dir, they are automatically in the CLASSPATH. You don't have to do anything special.
Having said that, when you put bean classes in the WEB-INF/classes, the whole Java world knows that these are beans without any package stmts, right!
Now there is a sticky thing with no-package bean classes.... . When you use bean without a package stmt, the App Server will look for the bean class in the same package as that of the generated Servlet code. And we don't know what package the generated servlet code is, so generally the JSP fails.
Bottomline, put your beans in a package and then access them. Ofcourse in this case you will put the bean class files in the WEB-INF/classes/mycom/mypackage/ directory which reflects the package stmt in your bean class.
Good luck.
- satya

Take a Minute, Donate an Hour, Change a Life
George Larry
Ranch Hand

Joined: Nov 07, 2001
Posts: 52
Maybe if I give you all the details of my bean-creation attempt...
I created a file called that had the bean stuff in it:
package meanBean;
public class testBean {
I saved it and ran javac to create testBean.class
I'm running this from the example dir so I place my files in the dir:
(I also tried placing the class file in:
From my .jsp file I try to call the bean:
<jsp:useBean id="myBean" scope="page" class="meanBean.testBean" />
But I'm getting an error:
Class meanBean.testBean not found.
Please let me know what I'm doing wrong. If you've already told me... I'm sorry, but I didn't get it- Would you mind trying again?
Thank you so much-
[ February 04, 2002: Message edited by: George Larry ]
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040


Since your package stmt for the code is:
package meanBean;
Your .class file (.java is not needed) should be in the dir
Let me know what happens. Right now I an not at my system so I can't try it.
Also if this doesn't work, pl. post the URL you are using to access the JSP and where you are placing the JSP.
Good luck.
- satya
sumana ar

Joined: Aug 06, 2003
Posts: 28
hello ..
i also had the same problem that george had with placing the .class files.
i've my .class file placed in
C:\Program Files\Apache Group\Tomcat\webapps\myfirstapp\WEB-INF\classes\test\userdata.class
where test is the name of the package.
my .jsp file placed in
C:\Program Files\Apache Group\Tomcat\webapps\ROOT\harit\
From my .jsp file I tried to call the bean:
<jsp:useBean id="emp" scope="page" class="test.userdata" />
but i'm getting an error..
package test does not exist
please help me where i'm doing an i need to set any CLASSPATH for running this JSP
thanks in advance
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Your JSP is in the ROOT web application, while your beans are in the "myfirstapp" web application. That won't work. Put the beans and the JSP in the same web application.

Ron Newman - SCJP 1.2 (100%, 7 August 2002)
sreekanth rach

Joined: Jan 02, 2003
Posts: 14
Hello Sumana!!
put class files under Install-Dir/webapps/ROOT/WEB-INF/classes/packagename/
put jsp files under Install-Dir/webapps/ROOT/packagename/
no additional classpath settings is needed.
hope, this helps u..
Bhavesh Ravjee

Joined: Jun 15, 2004
Posts: 11
Hi, I am having problems with storing the class file with tomcat 4.
I always get this error:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: -1 in the jsp file: null

Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] C:\Tomcat\work\Standalone\localhost\_\MyPackage\ cannot resolve symbol
[javac] symbol : class Calculator
[javac] location: package MyPackage
[javac] import MyPackage.Calculator;
[javac] ^
[javac] 1 error

Why is it pointing to the location "C:\Tomcat\work\Standalone\localhost\_\MyPackage\index_jsp".


With great power comes great responsibility!
I agree. Here's the link:
subject: Changing ClassPath
It's not a secret anymore!