• Post Reply Bookmark Topic Watch Topic
  • New Topic

package javax does not exist  RSS feed

 
utsav gupta
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I'm trying to compile a servlet using jdk1.6 i'e without using tomcat.
But on compiling the java file using javac command i get an error saying unable to import javax.servlet package.
Even though I hav set the claaspath to point to servlet-api.jar file correctly and I am able to locate it thru javap command.
Not just that I'm not able to import any other lpackage apart from java package.
Do we hav to set Classpath for some other jar file?
Do we need to install java sdk to compile a servelet or its ok to compile it thrugh jdk wen i hav set the classpath to correct files.
Ple reply its been 3 days since mindless googling no solution.

Thanks a lot.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
utsav gupta wrote:Even though I hav set the claaspath to point to servlet-api.jar file correctly

You have not. If you had, you would not be getting this error.
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Bear said, verify that you have set the classpath correctly.
 
Anurag Blore
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Utsav,

If you are trying to run from command line, I would suggst you to create a .bat file(if running from windows, you just need save a file as .bat file)
. And set the classpath in this file and execute this file before compiling your program. This is to make sure your path is set correctly.
 
utsav gupta
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is my classpath

C:\Documents and Settings\Administrator>echo %CLASSPATH%
.;C:\Program Files\Java\jre1.6.0_02\lib\ext\QTJava.zip;C:\Program Files\Java\jdk
1.6.0_02;C:\Program Files\Java\servlet-api.jar

i gave javap command and found the servlet class as well

also i'm not able to import any other package except java.*;
do we need to install jsdk?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The %CLASSPATH% environment variable will be ignored if you run javac.exe or java.exe with the -cp or -classpath or -jar argument.

Besides, what is the servlet-api.jar doing in your program files/java folder? That's not the place where it normally belongs. It should normally be part of the library of the Java EE application server implementation which you have installed (for example Tomcat). You normally add Tomcat/lib/servlet-api.jar to the classpath. Don't move libraries around and do not put them separate, this makes completely no sense.
 
utsav gupta
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks for your replies .
ya i did move libraries but only to make sure.
By the way i wud like to mention i hav only installed jdk1.6 and no other java kit.
I copied servlet-api.jar file from tomcat\lib to the above folder.
Also i'm not using -cp while executing javac.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.. ya .. wud .. hav ..

Sorry, my motivation to help you further has completely gone.
 
utsav gupta
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I apologize for my inapprpriate articulation of expressions as this is my first post on this site.
However I was more driven by communicating rather than conversating.
No offence intended but if these forms of english seem silly then terms like 'ranch' 'green horn' 'saloon' also doesnt make much sense to me in a java forum either Mr Sherriff.

Though I would like to mention my affection for this site has increased furhter more

I would be more care ful next time.

Regards
Utsav.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
utsav gupta wrote:However I was more driven by communicating rather than conversating.

Effective communication happens when real words are used. How does using fake words "drive communication"?

No offence intended but if these forms of english seem silly then terms like 'ranch' 'green horn' 'saloon' also doesnt make much sense to me in a java forum either Mr Sherriff.

Those are all real words. I do not understand the comparison.

Please read this for more information.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Effective communication happens when real words are used.


Respectfully I disagree.

Getting back to the original question, it should work the way you set it up. The only reason it should not find the package is when the class path is not properly set up.
Can you post the exact compilation error that you get? Still just posting the code and compilation error might give some clue as to whats missing!
 
Yogendra Joshi
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should normally have jsp-api and servlet-api.jar both set in the CLASSPATH variable of your machine. If thats done correctly, you are sure find the javax and javax.servlet.http packages when you run any servlet code.


Also , as Bauke has mentioned, if you use cp or classpath, it takes precedence over the CLASSPATH variable and moving jars is really a bad idea.

so add servlet-api and jsp-api so your classpath variable and try to compile your class. I am sure this is going to work.

Just in case if you feel why i am mentioning jsp-api too, well thats because when you proceed ahead in your knowledge on servlets and jsp, You would anyways need this to be included, so you better make this right now !

Regards,
Yogendra N Joshi
 
AsifAimen Iqbal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Utsav,
Try to set the path and the classpath as i mentioned below,
set path="Path To Your bin folder in jdk1.6";

set CLASSPATH=.;Path to the servlet-api.jar

I hope this may work out!!!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Mercs wrote:Respectfully I disagree.

You're right -- merely using real words does not guarantee good communications. I should have stated it as: Good communication is impossible when made-up words are used.

 
Marcus Halberstram
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ensure that servelt-api.jar exists. I found that several installatons of tomcat(4.1 and 5.5.27) do not have servlet-api.jar. It is called "servlet.jar".
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!