jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Enviornment Variables,classpath and path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Enviornment Variables,classpath and path" Watch "Enviornment Variables,classpath and path" New topic

Enviornment Variables,classpath and path

Aditya Godbole

Joined: Oct 17, 2008
Posts: 1

can anyone tell me the difference between classpath and path?

also what is an enviornment variable and why we are set environment varibale explicitly?

what is the use of CATELINA_HOME path I know that if we are not set it then error will come but what exactly the meaning of it?

please give me the solution.
[ October 17, 2008: Message edited by: Bear Bibeault ]
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1323

Welcome to Javaranch,

I hope this entry in FAQs will definitely helps to understand about classpath..

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

the PATH environment variable has been around a LONG time. I am pretty sure it pre-dates java. it is basically a list of directories that the operating system (windows, Unix...) uses to search through when you type a command.

it would really suck to have to type


every time you wanted to run the 'ls' command on unix, so the directory "/usr/local/bin" is put in your path. here is what my path looks like on one of our unix boxes:


Any time i type a command, the OS says "well, let's see if i can find an executable called 'ls' in the "/CISV1R4/scripts" directory. Nope? ok, how about in the "/CISV1R4/bjc" directory. Nope? how about in the..." and it keeps going until it finds it, or runs out of places to look.

so, your OS will use the PATH directory to find where the java executable file is so that can run. This is all done behind the scenes.

now... java needs to find class files to run. When you start the java program, you can explicitly state the location of your classfiles, but that gets old pretty quick. So, they came up with the CLASSPATH variable. java (once it starts) uses the CLASSPATH variable (in the same way the OS uses the PATH variable) to see where to look for you class files. Here is my CLASSPATH on one of our unix boxes:

/usr/WebSphere/AppServer/classes:/usr/WebSphere/AppServer/servlets:/home/cisdev/sqllib/java/db2java.zip:/usr/WebSphere/AppServer/lib:/usr/WebSphere/AppServer/lib/jsdk.jar:/usr/WebSphere/AppServer/lib/ibmwebas.jar:/usr/local/java/lib/classes.zip:/CISV1R4/bjc/classes:/usr/lpp/internet/server_root/java/lib/classes111.zip:/usr/lpp/mqm/java/lib/com.ibm.mq.jar:/usr/lpp/mqm/java/lib/com.ibm.mqjms.jar:/usr/lpp/mqm/java/lib/jms.jar:/usr/lpp/mqm/java/lib/jndi.jar:/usr/lpp/mqm/java/lib/:/usr/lpp/mqm /java/lib/com.ibm.mqbind.jar:/usr/lpp/mqm/java/lib/connector.jar:/home/cisdev/sqllib/samples/java/samples.zip:/usr/WebSphere/AppServer/lib/servlet.jar:/usr/WebSphere/AppServer/lib/ejs.jar:/usr/WebSphere/AppServer/lib/databeans.jar:/usr/WebSphere/AppServer/lib/idb.jar:/usr/WebSphere/AppServer/lib/ujc.jar:/usr/WebSphere/AppServer/lib/rowset.jar:/usr/WebSphere/AppServer/lib/WebJContextor.jar:/home/cistest/sqllib/java/db2java.zip:/home/cistest/sqllib/java/db2jcc.jar:/home/cistest/sqllib/java/sqlj.zi p:/home/cistest/sqllib/function:/home/cistest/sqllib/java/db2jcc_license_cu.jar:.

I don't want to type all those every time i run a java program. so, java knows to search all of those directories each time it is trying to find a class file. Notice the last directory in the list is a dot. That means 'search the current directory as well'. having a dot in your classpath can help solve a lot of issues.

if you are a beginner, I wouldn't worry about setting the classpath just yet. But if you do, make sure you have a dot in there somewhere (and note that the separator between directories varies by OS).

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Sumit Jindal

Joined: Oct 11, 2008
Posts: 3
If you go through your startup.bat or startup.sh file inside Tomcat/bin folder, you will find they are using this key to refer to the path (which depends on where you installed your tomcat) of the Tomcat folder.
So, you need to mention this path in environmental variables so that the batch file can get the actual path of your tomcat directory.

I agree. Here's the link: http://aspose.com/file-tools
subject: Enviornment Variables,classpath and path
It's not a secret anymore!