Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes setting the classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "setting the classpath" Watch "setting the classpath" New topic
Author

setting the classpath

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I've just downloaded jdk1.3.I want to know how to set the classpath so that i can compile program out side the directory.
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20528
    ∞

I'm moving this to Java in General (beginner)


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Sajan Joseph
Ranch Hand

Joined: Jan 05, 2001
Posts: 40
Originally posted by jayari:
I've just downloaded jdk1.3.I want to know how to set the classpath so that i can compile program out side the directory.

Please execute the steps given below to check Java installation :

Step 1 :Check Autoexec.bat file
Edit Autoexec.bat file in your root directory. ie; open autoexec.bat in Notepad or any other text editor you feel comfortable with :
Check the PATH
Check for the sentence given in red colour in the PATH environment variable :
For example :
PATH=%PATH%;.........;c:\<jdk directory>\bin;
where <jdk directory> is the directory in which you have installed the JDK(Java Development Kit).
This is typically c:\jdk1.3 if you have not installed it elsewhere.
So you can check for :
PATH=%PATH%;........;c:\jdk1.3\bin;
Check the CLASSPATH
Check for the sentence given in red colour in the CLASSPATH environment variable :

For example :
set CLASSPATH=%CLASSPATH%;c:\<jdk directory>\lib;c:\<jdk directory>\lib\tools.jar;
where <jdk directory> is the directory in which you have installed the JDK(Java Development Kit).
This is typically c:\jdk1.3 if you have not installed it elsewhere.
So you can check for :
set CLASSPATH=%CLASSPATH%;........;c:\jdk1.3\lib;c:\jdk1.3\lib\tools.jar

P.S : If you do not find a CLASSPATH environment setting then you can add the following line to the autoexec.bat file IMMEDIATELY AFTER YOUR PATH environment setting.

set CLASSPATH=%CLASSPATH%;c:\<jdk directory>\lib;c:\<jdk directory>\lib\tools.jar;
where <jdk directory> is the directory in which you have installed the JDK(Java Development Kit) (eg. : c:\jdk1.3).

Step 2 : Running the test program.
Open Notepad
Type the java program given below :
public class Test{
public static void main(String[] args){
System.out.println(" Hello World");
}
}

Make sure the program is typed exactly as it is shown above. The Capitalization is very important. Otherwise you will not get the desired output.

Go to MS DOS prompt :
Create a directory called test in C:\ : by executing the following command(given in red).
C:\>md test
(alternatively you can create the directory from Windows Explorer by clicking File--->New ----->Folder Folder name : test)

Save the file as Test.java in the test directory (Remember it should be Test.java (with Capital T) and not test.java)
(Windows Explorer : click File---->New---->SaveAs : Test.java)

If you are not in MS DOS prompt, Go to DOS prompt now (Select MS DOS Prompt from Start---> Programs---MS-DOS Prompt)
Change to test directory :
C:\>cd test

Type the command given in red to compile your program:
C:\> javac Test.java (Remember not test.java)
(The computer will not display anything if everything is fine. If there is anything wrong it will display an error message)

If everything is ok and you are back in DOS Prompt ie.; C:\> , then type the command given in red to run the program :

C:\>java Test (Remember - do not type Test.java or test)

If everything is OK the computer will display the message :

Hello World

Your java compiler is set up. No more trouble... Enjoy

If you get error messages instead, then you have trouble: Call the expert.
Hi I had send this mail to somebody long ago. Hope this will be useful to you in checking your installation.
SJ
Sajan Joseph
Ranch Hand

Joined: Jan 05, 2001
Posts: 40
Just refer to my previous reply to your message. If it looks cryptic, the reasons are
1. the red color is lost during uploading to java ranch.
2. All the tags '<'jdk directory '>' inside my original message have mysteriously diasappeared. HTTP has gobbled it up.
So where ever you find two backslashes(\) together (Eg : \\), pleade insert '<' jdk directory '>' while reading the message.
I hope this time HTTP will not swallow '<' & '>' :-)
SJ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting the classpath