• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error: Package javax.servlet not found

 
Seema Das
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have jsdk2.1. I have added c:\jsdk2.1\runner.jar as well as servlet.jar in the classpath. But while compiling the servlet class, I am getting error that Package javax.servlet is not found. and of course there are other errors following it because of this one.
Could anyone tell me how do I resolve this?
TIA
 
k b
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's there in your class path ? Can you copy and paste your classpath, so that we can help you.
Thanks,
 
Seema Das
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my classpath is:
C:\VisualCafeSE\Java\Lib;C:\VisualCafeSE\Java\Lib\SYMCLASS.ZIP;C:\VisualCafeSE\Java\Lib\CLASSES.ZIP;C:\VisualCafeSE\Java\Lib\COLLECTIONS.ZIP;C:\VisualCafeSE\Java\Lib\ICEBROWSERBEAN .JAR;C:\VisualCafeSE\Java\Lib\SYMTOOLS.JAR;C:\VisualCafeSE\swing-1.1\SWINGALL.JAR;C:\VisualCafeSE\Bin\Components\SFC.JAR;C:\VisualCafeSE\Bin\Components\SYMBEANS.JAR;C:\VisualCafeSE \Java\Lib\DBAW.ZIP;C:\VisualCafeSE\Bin\Components\DBAW_AWT.JAR;C:\VisualCafeSE\Bin\Components\Databind.JAR;C:\VisualCafeSE\Bin\Components\templates.jar;.;C:\jsdk2.1\runner.jar;C:\j sdk2.1\servlet.jar;.;

and path is:
C:\VisualCafeSE\Java2\Bin;C:\Program Files\Common Files\WebGain Shared;C:\VisualCafeSE\Bin;.;
thanks for help.
 
k b
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
make two bat files mycompile.bat and myrun.bat out of the follwing code and put in c: and try running it will tell you what class path you are using both at run time and compile time. You can take out remark statements after wards, they are there for usage instruction only. Hope this help.

// mycompile.bat
@echo OFF
SET SOURCE=c:\SeemaDas\Source
SET DEPLOY=c:\where you want your compiled class to go( full path example:c:\myapp\web-inf\classes)
SET cp=%DEPLOY%;c:\jsdk12\servlet.jar;c:\any other jars you need with ; separated
echo Your Compile Time ClassPath:
echo %cp%

IF "%1"=="" goto FULL
IF "%1"=="all" goto ALL
:SINGLE
javac -classpath %cp% -d %DEPLOY% %1
goto END

:FULL
javac -classpath %cp% -d %DEPLOY% *.java
goto END
:ALL
javac -classpath %cp% -d %DEPLOY% %SOURCE%\util\*.java
javac -classpath %cp% -d %DEPLOY% %SOURCE%\common\*.java
goto END
:END
rem to compile a single java source : mycompile.bat myjava.java
rem all java sources on specified subdirectories mycompile.bat all
rem if want to compile all java sources only under c:\SeemaDas\Source directory mycompile.bat
// myrun.bat
@echo OFF
SET DEPLOY=c:\where you want your compiled class to go( full path example:c:\myapp\web-inf\classes)
SET cp=%DEPLOY%;c:\jsdk12\servlet.jar;c:\any other jars you need with ; separated
echo Your Run Time ClassPath:
echo %cp%
java -cp %cp% %1 %2 %3 %4 %5
goto END
:END
rem to run the pgm type myrun.bat myjava parma1(if any) param2(if any) ... param4(if any)
rem %1 %2 %3 %5
 
Seema Das
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks k b but I am really confused now.
I just downloaded and installed jsdk2.1 on other WindowsNT machine. So its brand new now.
After this, could someone tell me how do I configure jsdk, where do I need to keep my servlets, how do I call the servlets etc. etc.
I have already written one program but can't compile or run it because of all these problems. Please help.
TIA
 
Tim Holloway
Saloon Keeper
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For building java projects outside of the WebGain IDE, I recommend Ant (http://jakarta.apache.org/ant). It understands Java's special needs. It also isn't OS-dependent the way "make" is, and I actually found it easier to use than "make". Here's my entire build file for a project with servlets and JSPs. Once it's done, the "class" directory can be jarred (also an Ant command) or copied to the server's project class directory.
<project name="listopt" default="all" basedir=".">
<target name="all">
<javac srcdir="." destdir="class">
<classpath>
<pathelement location="libs/retepPDF.jar"/>
<pathelement location="libs/servlet.jar"/>
<pathelement location="/usr/local/lib/ejb.jar"/>
<pathelement location="libs/Contents.jar"/>
<pathelement location="libs/MailingList.jar"/>
<pathelement location="libs/Category.jar"/>
<pathelement location="libs/CategoryList.jar"/>
<pathelement location="class"/>
</classpath>
</javac>
</target>
</project>
To build INSIDE WebGain, just add the servlet.jar on the project options Input Files page.
You didn't say what server you're going to eventually use the generated classes in, but the Sun standard is to put the classes in the server's WEB-INF/classes directory and the jar libraries in the WEB-INF/lib directory.
 
Seema Das
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Tim.
Well, eventhough the classpath contains VisualCafe directories, I am not using VisualCafe for building my Java applications. I am relatively new to Java (just got my programmer certification) and stil learning. SO I am just using notepad.
These projects are just for myself so I just want to run them on my Windows NT machine.
The initial error I got was on my laptop which has jsdk2.1 beta version and surprisingly there is a difference in the beta and production versions of jsdk2.1 So I am starting it alll over again on other machine.
Now I have downloaded jsdk2.1 (of course latest version) but
donno how to configure it.
Could someone give me step by step process to do this?
Thanks
 
Dipti Alurkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Seema,
The simplest way to run servlets is using the servletrunner that is bundled alongwith the jsdk download.
The servletrunner.exe is found in the c:\jsdk2.1\bin directory
where c:\jsdk2.1 is the directory in which you have installed the jsdk.
Compile your servlet and place it in the c:\jsdk2.1\examples directory.
Then start the servletrunner, either by double-clicking on the icon or by typing servletrunner on the DOS prompt.
make sure that the servletrunner.exe is in your path, so that you can invoke it from any other directory too.
include the servlet.jar in your classpath too.
To run the servlet,
Open a browser, and type http://localhost:8080/servlet/ServletName
where ServletName = name of your servlet.
Hope this helps.
Dipti
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic