aspose file tools*
The moose likes Servlets and the fly likes Servlet programming - Jar files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet programming - Jar files" Watch "Servlet programming - Jar files" New topic
Author

Servlet programming - Jar files

Raj Puri
Ranch Hand

Joined: Apr 24, 2003
Posts: 189
I have import stmt (like import org.apache.* etc ) on top of a servlet so I believe that I need to have those files unjarred in classes directory for servlet to compile. Now at run time do I still need jar file to run the servlet. My servlet does not compile unless I unjar and it does not run unless I put jar in lib. Sound weird. I should not be needing to do unjar whiel compile.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You're quite right: you don't need to unjar it to compile or run, but in both cases you need to make it available on the classpath.

The trick here is that the compile time and runtime classpath (for app servers) is different. If you compile from the command line you need to add the jar (and the whole jar, not just the path to the jar) to your classpath, but at runtime it will find the jar in the WEB-INF/lib directory.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You don't need to unjar anything to compile or run a servlet.
You just need to have the needed jar files on your classpath.

Unlike with classes, which only need the parent directory on the classpath, jar files have to be added directly to the classpath for their contents to be accessible.

Example:
export CLASSPATH=$CLASSPATH:/usr/lib/j2ee.jar

or for windows:

set CLASSPATH=%CLASSPATH%;c:\j2ee.jar


Which conatiner are you using?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Servlet programming - Jar files
 
Similar Threads
Doubt on packaging the project
Problem Creating Executable JAR
regarding JAR files
Problem in wrtitng JAR File
Tomcat 4.0 problem with Filter class