Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Setting Classpath for JSDK

Posted on 2000-03-07
Last Modified: 2013-11-23
How do I set the Classpath for JSDK in Solaris. I am very new to
using Servlets. I installed  JSDK2.1 in Solaris. But evertime I compile
any servlet, I get the following error:

"SessionServlet.java:25: Package javax.servlet not found in import.
import javax.servlet.*;
SessionServlet.java:26: Package javax.servlet.http not found in import.
import javax.servlet.http.*;
SessionServlet.java:37: Superclass HttpServlet of class SessionServlet not found.
public class SessionServlet extends HttpServlet {"


I have a deadline to meet, somebody please help me and let me know
what I need to do in order to get this servlets compiling and executing.
Question by:bmeena71
  • 9
  • 8

Accepted Solution

cheneque earned 50 total points
ID: 2593004
You can add the file servlet.jar to the CLASSPATH enviroment variable. For example:

CLASSPATH = $CLASSPATH:/opt/jsdk1.2/servlet.jar

or you can edit the .java_wrapper file in the java/bin subdirectory adding the complete path of the servlet.jar file.

If you need anymore just say it.

Author Comment

ID: 2593441
Hi Cheneque,

Thanks a lot for responding. I have installed
JSDK version 2.0 and I could not find any servlet.jar
file. I could find jsdk.jar

And also where should I set the classpath. Is there
a file I should add this in. As of now the classpath
settings exist in a file called  .profile

Your help is appreciated.

Expert Comment

ID: 2593539
Yea, you can add the CLASSPATH enviroment variable in your .profile file. but I recommend you use a enviroment configuration script if you are developing various applications.

I´m using jdk1.1.7 and the shell csh and I created a file called "enviroment.sh", in this file I add all the directories or jar files that I use for my applications. My enviroment.sh file look lije this:

#here is the classpath for my applications.
setenv CLASSPATH /home/cheneque/applications/classes:/home/cheneque/lib/servlets.jar:/home/cheneque/lib/jndi.jar
I call this file using the following command.

$ source enviroment.sh

In this way I can configure a lot of applications in a unique UNIX account.

P.D. the servlets.jar file is part of the jsdk2.1
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center


Author Comment

ID: 2598004
Hi Cheneque,

I tried what you recommended. I created an env file and did
set the classpath exactly as you have mentioned. But I get
"setenv not found" and when I do 'source env.sh' I get "source not
found" errors.

My company's unix admin is out of town and I just have basic
Unix knowledge.

I still am at a loss of how to configure this.  Any help??

Expert Comment

ID: 2598203
what sell are you using?
-- csh
-- bash
-- sh
or another one? you can know this whit the following command:
$ echo $SHELL

I´m running "csh" and it works fine if you are running another shell maybe the thinks are diferent. see the man pages of your shell for more information.

Maybe you are using "sh" or "bash" you can use "export" instead "setenv".

Say me the shell and your subdirectories and I create a enviroment file for you.

Author Comment

ID: 2598323
When I do echo $SHELL  I get /bin/sh

and the directory where JSDK2.0 installed is as follows


Looking forward for your reply.

Thanks for being so patient with me.


Author Comment

ID: 2602324
Would you still be able to help me.
thanks- M

Expert Comment

ID: 2602665
Hi, I create a script for you, but you can´t use the enviroment variables of the sell from a file because you ar running "sh" but it dont matter. This script you have to complete with your options:

---------- cut after this line ---------------------

#Here is the  jsdk classpath

#Here we put the application classpath
#(This line is comented because you have to fill this line with the classpath of the application that
# you are developming)

#We set the complete application classpath and libraries

#Now we Export the variables

#At this moment we are ready to start the application server,
#I'm using weblogic and to start it i put the following line
# java weblogic.T3Server &
#This is FOR ME you have to write the correct line or if you have a previus
# script to start your application server put this here.

----------------------finish ----------------

If you change to "csh" you can use the following script

---------------------------------- cut after this line -----------------------

#Here is the  jsdk classpath
setenv SERVLETS_CLASSPATH /jrun2.2/JSDK2.0/lib/jsdk.jar

#Here we put the application classpath
#(This line is comented because you have to fill this line with the classpath of the application that
# you are developming)
setenv APPLICATION_CLASSPATH here_put_your_options_be_careful_with_the_blank

#We set the complete application classpath and libraries

---------------finish -----------------

With the second script you use the "source" comand to read it, the source comand is avalible when you are in csh

Good luck

Expert Comment

ID: 2602669
Note: With the "sh" option you can´t read variables to the shell from a script, you have to call the application in the script to make the enviroment works with your aplication

Author Comment

ID: 2606444

I did as you said and I am able to compile the servlets now. Thanks a lot for
your help.

Now when I execute the servlet - a servlet called SnoopServlet from the examples this is what I get

"java.lang.NoSuchMethodError: javax.servlet.ServletResponse: method getWriter ()Ljava/io/PrintWriter; not
found at SimpleServlet.doGet(SimpleServlet.java:48) * at
javax.servlet.http.HttpServlet.service(HttpServlet.java:252) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:330) at
sun.servlet.netscape.NSRunner.run(NSRunner.java:144) at
netscape.server.applet.ServerApplet.handleRequest(ServerApplet.java:69) at
netscape.server.applet.HttpApplet.handleRequest(HttpApplet.java:680) "

Am I still missing something here.

Thanks a lot,

Expert Comment

ID: 2613555
The problem is with the class java.io.PrintWriter, maybe you are ommiting the classes.zip archive in your classpath.

If you are using the -classpath option when you start your server you have to put all the files.


Expert Comment

ID: 2613561
the classes.zip archive are in the $JAVA_HOME/lib subdirectory

Author Comment

ID: 2614057

I could find the archive file classes.zip

the directory path for that is /usr/java1.1/lib/classes.zip

My alread existing classpath looks like this:

CLASSPATH=/jrun2.2/JSDK2.0/lib/jsdk.jar; export CLASSPATH

echo "\nWelcome home, Meena!\n"

Now I added the classpath for the classes.zip file and it looks as

CLASSPATH=/jrun2.2/JSDK2.0/lib/jsdk.jar:/export/home/mxb80/java1.1/lib/classes.zip; export CLASSPATH

echo "\nWelcome home, Meena!\n"

Now I execute the servlet called SimpleServlet, I get the same error message.  Please let me know if I am still doing something wrong/


Expert Comment

ID: 2618086

Maybe you don´t have the jsdk, try downloading the jsdk 2.0 form the javasoft site and puting the servlet.jar file in your CLASSPATH.

Other solution is install netbeans or forte for develpment. both IDE´s have a servlet developmet module and the good news are:  both applications are for free in the http://www.javasoft.com site.

You can develop, debug and run your servlets in a testing enviroment.


Author Comment

ID: 2620563

This is a very good recommendation you have told me. Thanks a lot
for that. I also happened to find out what was going wrong in my
servlet. I am using an old version of Netscape(3.63) and it doesn't
support  PrintWriter I believe and that is the reason I was getting
"java.lang.NoSuchMethodError: javax.servlet.ServletResponse: method getWriter  ()Ljava/io/PrintWriter; not found" ---error.

Instead I changed my program and used. getOutputStream() method
and I was able to successfully compile and execute it. But I will
now download Netbeans or Forte. This way I will be able to test
my servlets.

My next step is to connect to database thru jdbc:odbc.  I will get in
touch with you if I encounter any problems.

Thanks a lot for all your help.

Expert Comment

ID: 2624313
Net beans or forte have modules to use JDBC and wizards to connect to a data base. Is a very good tool !!!

Good look !!

Author Comment

ID: 2624933

Once again, thankx a lot for giving me excellent tips.

When my code for servlet is being executed, "oracle.jdbc.driver.OracleDriver" throws a nullPointerException.

My code gets compiled and when I am tail-ing the error log,
I noticed that when it comes to the above line of "oracle.jdbc..."
I get a null value.  

what am I missing?

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
even odd program using while loop 3 60
How to execute a Python program and gather return output in Java 2 40
throw exception 21 58
jboss wildfly 10.1 10 228
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question