File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes classpath difference? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "classpath difference?" Watch "classpath difference?" New topic

classpath difference?

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Hi All,

i have my servlet-api.jar in D:\servlet

if i set this path in environmental variable(only path value..not calsspath)..then the jar file is not recognized(when i try to compile)
..but when i put it into classpath also..its working

for compiling a java file,only path is enough know ?(core java file(not servlet-api.jar))...

please any one can explain me...
thanks & regards,
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Your PATH variable is what the system used to find executables (like java and javac). The CLASSPATH variable is used by java and javac to find Java classes.

So, there in no need to put servlet-api.jar on your PATH environment variable.
It does need to be added to your CLASSPATH environment variable in order for javac to find the servlet api classes.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

for compiling a java file,only path is enough know ?

that depends...

the path variable tells your operating system (Windows, Unix, whatever...) where to look for programs you want to run. when you type "javac", the OS says "hmmm... i need to find the javac.exe program. it's not in the current directory. let me check all the directories listed in the PATH environment variable (in the order they are listed) and see if i can find it."

that is the ONLY thing the PATH variable is used for. it really has nothing to do with how java works - it's only used to find the executables.

the CLASSPATH variable is used by the java programs to find various class files.

So, depending on what you are doing, you may not need to set either, you may need to set both, or you may need to set only one. although you're almost ALWAYS going to update your PATH to make life easier.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

thanks a lot ...Ben Souther and fred rosenberger
I agree. Here's the link:
subject: classpath difference?
It's not a secret anymore!