aspose file tools*
The moose likes Beginning Java and the fly likes path and class path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "path and class path" Watch "path and class path" New topic
Author

path and class path

dhanashree ghaskadbi
Greenhorn

Joined: Apr 26, 2001
Posts: 6
What is a path and classpath?
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
PATH and CLASSPATH are two Windows variables you set in AUTOEXEC.BAT to allow you to compile and run Java programs.
Setting PATH allows you to type

java KnightsTour
at the
C:\>
prompt, and run your class file KnightsTour.class. Without setting this PATH variable, you would have to type

jdk1.3\bin\java KnightsTour
at the C:\> prompt every time. (In this example, your PATH variable would have to contain "C:\jdk1.3\bin".)
Just as the PATH variable tells Windows where to look for the command you're passing to it ("java"), the CLASSPATH variable tells Java where to find the top level of class files you're passing to it. For example, I have my CLASSPATH set to "C:\Java\docs". So if I put a source file in my C:\Java\docs folder, I type
javac Source.java
, and Java knows to look for the file in C:\Java\docs. Say I have another source file, Source2.java, that I've indicated in my program lives in package com.artmetzer. Then, I need to do the following:
1) Create a folder called "com" in the existing folder C:\Java\docs.
2) Create a folder called "artmetzer" in the just-created folder C:\Java\docs\com.
3) Save Source2.java in C:\Java\docs\com\artmetzer.
4) At the MS-DOS prompt, I change directories to my classpath directory, C:\Java\docs.
4) At the MS-DOS prompt, since my PATH and CLASSPATH variables are set, I type at the

C:\Java\docs>
prompt

javac com\artmetzer\Source2.java
to compile Source2.java. Then, after it compiles successfully, I type at the

C:\Java\docs>
prompt

java com.artmetzer.Source2
to run the code in Source2.
Hope this helps, Dhanashree, and good luck.
Art
 
jQuery in Action, 2nd edition
 
subject: path and class path