• Post Reply Bookmark Topic Watch Topic
  • New Topic

Server side folders "/classes" and "/lib"

 
Michael OBrien
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a web application, classes and beans used by JSP can be placed in a jar file and stuck in the /WEB-INF/lib directory. Alternatively, they can be placed in a directory tree under /WEB-INF/classes. It seems that under BEA Weblogic, once a web application context has been defined, these two folders are automatically in the classpath.
IS THIS PART OF THE SERVLET SPEC?
 
Karl Moss
Author
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this is part of the servlet spec. This is from the Servlet 2.3 spec (final version), Chapter 9 (web applications), section 9.5:
"The contents of the WEB-INF directory are:
- The /WEB-INF/web.xml deployment descriptor
- The /WEB-INF/classes/ directory for servlet and utility classes. The classes in this directory must be available to the application class loader.
- The /WEB-INF/lib/*.jar area for Java ARchive files. These files contain servlets, beans, and other utility classes useful to the web application. The web application class loader must be able to load classes from any of these archive files"
 
Michael OBrien
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Karl!
I did notice those sections of servlet spec 2.3. I guess what I was wondering is if the /classes and /lib folders were automatically included in the container classpath according to the spec, or if this behavior was container specific.
For example, if I create a jsp that references a class named com.myco.util.UsefulBean and I place UsefulBean.class /WEB-INF/classes/com/myco/util then, do containers handle setting up the classpath when a web application context is created?
I was testing with weblogic, and found that if the environment WEBLOGIC_CLASSPATH specifies a folder, I can put com/myco/util/UsefulBean.class in that folder and access the bean from jsp using either:
<jsp:usebean> or new.
However, if I insert com/myco/util/UsefulBean.class in the default server context under WEB-INF\classes, I get a Cannot resolve symbol error.
But, if I insert com/myco/util/UsefulBean.class in a web application servlet context other than the default context, then I can access the bean from jsp's without any problem.
Which led me to the hunch...Setting up a web application context in Weblogic automatically takes care of including WEB-INF/lib and WEB-INF/classes in a classpath used by the container class loader.
Then, I was wondering if this is container specific or if I can move a web app from container to container and not have to worrry about the classpath.
I think further testing in other containers is probably the road to take to answer this question.
Thanks for any thoughts.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Definately, anything under WEB-INF will be in the "class finding path"... which is not necessarily the same as the system's CLASSPATH. But as the spec pointed out... those classes in the WEB-INF directory **shall be available**, and you can 'port' your webapp between containers, and not have to further worry about CLASSPATH.

That is... if you container is compliant with the spec, which at least *one* of them is famous for not being.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!