Farzad Akbarnejad
asked on
Problem with placing classes in root of WEB-INF\classes instead of WEB-INF\classes\package
Hello,
I am learning JSP and I want to run the Date example of J2EE Tutorial using Tomcat.
I am using JBuilder 9.0 with JDK 1.4 without any enviornment variabke setting in My Computer except the JAVA_HOME set.
My Date JSP has two classes: MyDate and MyLocales. When I placed them in a package like datepkg I haven't any problem. But when I place these classes on the root I got the following error when I want to run my jsp using Tomcat 4.1:
"C:\Program Files\JBuilder9\jdk1.4\bin \javaw" -classpath "C:\Program Files\JBuilder9\thirdparty \jakarta-t omcat-4.1. 24-LE-jdk1 4\bin\boot strap.jar; C:\Program Files\JBuilder9\jdk1.4\lib \tools.jar " -Dcatalina.home="C:/Progra m Files/JBuilder9/thirdparty /jakarta-t omcat-4.1. 24-LE-jdk1 4" org.apache.catalina.startu p.Bootstra p -config "C:\Documents and Settings\Farzad Akbarnejad\My Documents\Training\JSP\Dat eJSP\Tomca t\conf\ser ver8080.xm l" start
Apr 27, 2004 3:07:24 PM org.apache.coyote.http11.H ttp11Proto col init
INFO: Initializing Coyote HTTP/1.1 on port 8080
Starting service Tomcat-Standalone
Apache Tomcat/4.1.24-LE-jdk14
HostConfig[localhost]: Deploying configuration descriptor jb--default.xml
WebappLoader[]: Deploying class repositories to work directory C:\Documents and Settings\Farzad Akbarnejad\My Documents\Training\JSP\Dat eJSP\Tomca t\work
WebappLoader[]: Reloading checks are enabled for this Context
StandardManager[]: Seeding random number generator class java.security.SecureRandom
StandardManager[]: Seeding of random number generator has been completed
StandardWrapper[:default]: Loading container servlet default
StandardWrapper[:invoker]: Loading container servlet invoker
HostConfig[localhost]: Deploying configuration descriptor jb-datejsp.xml
WebappLoader[/datejsp]: Deploying class repositories to work directory C:\Documents and Settings\Farzad Akbarnejad\My Documents\Training\JSP\Dat eJSP\Tomca t\work\dat ejsp
WebappLoader[/datejsp]: Deploy class files /WEB-INF/classes to C:\Documents and Settings\Farzad Akbarnejad\My Documents\Training\JSP\Dat eJSP\datej sp\WEB-INF \classes
WebappLoader[/datejsp]: Reloading checks are enabled for this Context
StandardManager[/datejsp]: Seeding random number generator class java.security.SecureRandom
StandardManager[/datejsp]: Seeding of random number generator has been completed
StandardWrapper[/datejsp:d efault]: Loading container servlet default
StandardWrapper[/datejsp:i nvoker]: Loading container servlet invoker
Apr 27, 2004 3:07:25 PM org.apache.coyote.http11.H ttp11Proto col start
INFO: Starting Coyote HTTP/1.1 on port 8080
Compile failed; see the compiler error output for details.
at org.apache.tools.ant.taskd efs.Javac. compile(Ja vac.java:8 42)
at org.apache.tools.ant.taskd efs.Javac. execute(Ja vac.java:6 82)
at org.apache.jasper.compiler .Compiler. generateCl ass(Compil er.java:31 7)
at org.apache.jasper.compiler .Compiler. compile(Co mpiler.jav a:370)
at org.apache.jasper.JspCompi lationCont ext.compil e(JspCompi lationCont ext.java:4 73)
at org.apache.jasper.servlet. JspServlet Wrapper.se rvice(JspS ervletWrap per.java:1 90)
at org.apache.jasper.servlet. JspServlet .serviceJs pFile(JspS ervlet.jav a:295)
at org.apache.jasper.servlet. JspServlet .service(J spServlet. java:241)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 853)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:247 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:1 93)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:256)
at org.apache.catalina.core.S tandardPip eline$Stan dardPipeli neValveCon text.invok eNext(Stan dardPipeli ne.java:64 3)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:480)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 95)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:191)
at org.apache.catalina.core.S tandardPip eline$Stan dardPipeli neValveCon text.invok eNext(Stan dardPipeli ne.java:64 3)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:480)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 95)
at org.apache.catalina.core.S tandardCon text.invok e(Standard Context.ja va:2415)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:180 )
at org.apache.catalina.core.S tandardPip eline$Stan dardPipeli neValveCon text.invok eNext(Stan dardPipeli ne.java:64 3)
at org.apache.catalina.valves .ErrorDisp atcherValv e.invoke(E rrorDispat cherValve. java:171)
at org.apache.catalina.core.S tandardPip eline$Stan dardPipeli neValveCon text.invok eNext(Stan dardPipeli ne.java:64 1)
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:172 )
at org.apache.catalina.core.S tandardPip eline$Stan dardPipeli neValveCon text.invok eNext(Stan dardPipeli ne.java:64 1)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:480)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 95)
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :174)
at org.apache.catalina.core.S tandardPip eline$Stan dardPipeli neValveCon text.invok eNext(Stan dardPipeli ne.java:64 3)
at org.apache.catalina.core.S tandardPip eline.invo ke(Standar dPipeline. java:480)
at org.apache.catalina.core.C ontainerBa se.invoke( ContainerB ase.java:9 95)
at org.apache.coyote.tomcat4. CoyoteAdap ter.servic e(CoyoteAd apter.java :223)
at org.apache.coyote.http11.H ttp11Proce ssor.proce ss(Http11P rocessor.j ava:594)
at org.apache.coyote.http11.H ttp11Proto col$Http11 Connection Handler.pr ocessConne ction(Http 11Protocol .java:392)
at org.apache.tomcat.util.net .TcpWorker Thread.run It(PoolTcp Endpoint.j ava:565)
at org.apache.tomcat.util.thr eads.Threa dPool$Cont rolRunnabl e.run(Thre adPool.jav a:619)
at java.lang.Thread.run(Threa d.java:536 )
Thanks
-FA
I am learning JSP and I want to run the Date example of J2EE Tutorial using Tomcat.
I am using JBuilder 9.0 with JDK 1.4 without any enviornment variabke setting in My Computer except the JAVA_HOME set.
My Date JSP has two classes: MyDate and MyLocales. When I placed them in a package like datepkg I haven't any problem. But when I place these classes on the root I got the following error when I want to run my jsp using Tomcat 4.1:
"C:\Program Files\JBuilder9\jdk1.4\bin
Apr 27, 2004 3:07:24 PM org.apache.coyote.http11.H
INFO: Initializing Coyote HTTP/1.1 on port 8080
Starting service Tomcat-Standalone
Apache Tomcat/4.1.24-LE-jdk14
HostConfig[localhost]: Deploying configuration descriptor jb--default.xml
WebappLoader[]: Deploying class repositories to work directory C:\Documents and Settings\Farzad Akbarnejad\My Documents\Training\JSP\Dat
WebappLoader[]: Reloading checks are enabled for this Context
StandardManager[]: Seeding random number generator class java.security.SecureRandom
StandardManager[]: Seeding of random number generator has been completed
StandardWrapper[:default]:
StandardWrapper[:invoker]:
HostConfig[localhost]: Deploying configuration descriptor jb-datejsp.xml
WebappLoader[/datejsp]: Deploying class repositories to work directory C:\Documents and Settings\Farzad Akbarnejad\My Documents\Training\JSP\Dat
WebappLoader[/datejsp]: Deploy class files /WEB-INF/classes to C:\Documents and Settings\Farzad Akbarnejad\My Documents\Training\JSP\Dat
WebappLoader[/datejsp]: Reloading checks are enabled for this Context
StandardManager[/datejsp]:
StandardManager[/datejsp]:
StandardWrapper[/datejsp:d
StandardWrapper[/datejsp:i
Apr 27, 2004 3:07:25 PM org.apache.coyote.http11.H
INFO: Starting Coyote HTTP/1.1 on port 8080
Compile failed; see the compiler error output for details.
at org.apache.tools.ant.taskd
at org.apache.tools.ant.taskd
at org.apache.jasper.compiler
at org.apache.jasper.compiler
at org.apache.jasper.JspCompi
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at org.apache.jasper.servlet.
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.C
at org.apache.coyote.tomcat4.
at org.apache.coyote.http11.H
at org.apache.coyote.http11.H
at org.apache.tomcat.util.net
at org.apache.tomcat.util.thr
at java.lang.Thread.run(Threa
Thanks
-FA
ASKER
Yes. I take them out of their package and place them in root and remove package statement from .java files and recompile them.
Thanks
-FA
Thanks
-FA
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When your JSP is compiled it is put into a package (dependent on the application server.) This put them into a different package to your java classes (which are compiled into the unnamed package).
You *may* be able to get things working by explicitly importing the classes ones by one:
<%@ page import="MyDate, MyLocales" %>
....
But, it would be better to leave the classes with a package statement, then copy the .class files into the classes subdirectory of your web app.
e.g.
package foo.bar;
public class MyDate {....}
Compile, and move to:
WEB-INF/classes/foo/bar/My Date.class
where WEB-INF is under the root of your web application.
You *may* be able to get things working by explicitly importing the classes ones by one:
<%@ page import="MyDate, MyLocales" %>
....
But, it would be better to leave the classes with a package statement, then copy the .class files into the classes subdirectory of your web app.
e.g.
package foo.bar;
public class MyDate {....}
Compile, and move to:
WEB-INF/classes/foo/bar/My
where WEB-INF is under the root of your web application.
...you would then have to import the foo.bar package:
<%@ page import="foo.bar.*" %>
<%@ page import="foo.bar.*" %>
ASKER
searlas,
I test it with importing classes before. it give
"index.jsp": Error #: 200 : '.' expected
error in JBuilder. So I placed them in package.
Thanks
-FA
I test it with importing classes before. it give
"index.jsp": Error #: 200 : '.' expected
error in JBuilder. So I placed them in package.
Thanks
-FA
ASKER
But I think that we can use beans without packaging them. Is there any way?
-FA
-FA
I don't think so...
Javabeans must be in a package that's one of the rules. Is there a reason you don't want to put your code into packages?
Ghost
Javabeans must be in a package that's one of the rules. Is there a reason you don't want to put your code into packages?
Ghost
ASKER
>>Is there a reason you don't want to put your code into packages?
Just for learning :-)
-FA
Just for learning :-)
-FA
ah well I was always taught that java programmers must place there code into packages for organizational purposes.
So I would suggest that you get used to that type of programming style so you can make good habits :)
there is nothing worse then 4 months later another co-worker has to go through your spagetti code and have to ask you to explain what you did and why you did it. I know it's happened to me several time :) So if I was you I would stick to writing structured code :)
Hope that helps,
Ghost
So I would suggest that you get used to that type of programming style so you can make good habits :)
there is nothing worse then 4 months later another co-worker has to go through your spagetti code and have to ask you to explain what you did and why you did it. I know it's happened to me several time :) So if I was you I would stick to writing structured code :)
Hope that helps,
Ghost
You should follow Ghost's advice, but for reference:
Section 8.2 of the JSP 1.2 specification states:
The JSP container creates a JSP page implementation class for each JSP page.
The name of the JSP page implementation class is implementation dependent.
The JSP page implementation object belongs to an implementation-dependent
named package. The package used may vary between one JSP and another, so
minimal assumptions should be made. The unnamed package should not be used
without an explicit import of the class.
(i.e. you CAN use classes from the unnamed package)
Section 8.2 of the JSP 1.2 specification states:
The JSP container creates a JSP page implementation class for each JSP page.
The name of the JSP page implementation class is implementation dependent.
The JSP page implementation object belongs to an implementation-dependent
named package. The package used may vary between one JSP and another, so
minimal assumptions should be made. The unnamed package should not be used
without an explicit import of the class.
(i.e. you CAN use classes from the unnamed package)
searlas is right it can be done,
but and please experts correct me if I'm wrong..
tomcat version 5.x says that class files MUST be in a package..
so you might as well get used to it since that's the future.
Ghost
but and please experts correct me if I'm wrong..
tomcat version 5.x says that class files MUST be in a package..
so you might as well get used to it since that's the future.
Ghost
I had no problems with this:
Mank.java (compile and copy to WEB-INF\classes)
public class Mank {
public String getMessage() {
return "some message";
}
}
ugh.jsp:
<%@ page import="Mank" %>
<%= new Mank().getMessage() %>
Works fine.
Mank.java (compile and copy to WEB-INF\classes)
public class Mank {
public String getMessage() {
return "some message";
}
}
ugh.jsp:
<%@ page import="Mank" %>
<%= new Mank().getMessage() %>
Works fine.
Ghost,
Got a reference for that, out of interest?
Got a reference for that, out of interest?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
great I was busy for a second didn't have time to going,
but yup I agree, :c)
Ghost
but yup I agree, :c)
Ghost
was there anything else?
Ghost
Ghost
As I said originally your classes/beans *must* be in packages :)
Are the java files in a package too?
Do you take them out of their own package and recompile before you try to move them to WEB-INF/classes?
Tim