wood burning stoves*
The moose likes Cattle Drive and the fly likes Compiling in the cmd prompt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Compiling in the cmd prompt" Watch "Compiling in the cmd prompt" New topic
Author

Compiling in the cmd prompt

Alex Wood
Greenhorn

Joined: Jan 06, 2008
Posts: 2
How do you set up the path/classpath to be able to utilize the Java SDK? I've used IDEs before, but never have been able to compile or run code through the cmd prompt w/out using another server (telnet/putty). Sorry to ask such a stupid question, thanks for your help!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Hi Alex. Welcome to JavaRanch. Your question isn't very specific as to which OS you're using or what you've tried so far, so I can't give a very specific answer.

Here are the directions from the initial CattleDrive page:
Download the JDK 5.0 (also known as the jdk-1.5.0) from Sun. You don't need the IDE or other stuff, just the plain ole jdk.

It is possible that once you have installed the JDK, everything will work fine as is. If you are not one of the lucky ones, you may need to adjust your PATH and CLASSPATH environment variables. On my windows machine, my PATH includes

C:\Program Files\Java\jdk1.5.0_14\bin

and my CLASSPATH is set to

.;C:\java (notice the dot before the first semicolon)

I put all of my stuff into a directory called java (off of my root, C:\, in Windows and off of my home directory in unix).

Here is a program that you can cut and paste to make sure that you have everything set up correctly. Make sure you put it into a file called HelloWorld.java (case is important! even on Windows computers):

<code>public class HelloWorld
{
public static void main( String[] args )
{
System.out.println("hello world!");
}
}</code>

Make sure that you paste this into a text editor (like notepad) and not a word processor. A word processor will stick a bunch of extra formatting text into the file.

Pull up a console (DOS) or terminal window and put the HelloWorld.java file into your java directory. Make the java directory your current directory. Type

javac HelloWorld.java

and press enter. Remember: case is still very important, even on Windows computers. If the program compiles without flaw, you will get your command prompt back. Otherwise, go to the Cattle Drive (java college) forum and tell us what went wrong.

To run your program, type

java HelloWorld

and press enter. You should then see "hello world!" on your screen.
[ January 07, 2008: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
Originally posted by Marilyn de Queiroz:
...

Here are the directions from the initial CattleDrive page:
Download the JDK 5.0 (also known as the jdk-1.5.0) from Sun.
...


I don't know if Alex is doing the Cattle Drive assignments, so it might not matter for him, but...

...is the Cattle Drive move to JDK 5 already official? On this page it still looks like jdk 1.4:

http://www.javaranch.com/java-college.jsp


[ January 07, 2008: Message edited by: Pauline McNamara ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
No, not official yet ...
Good point.
Alex Wood
Greenhorn

Joined: Jan 06, 2008
Posts: 2
I'm running windows XP. I read those instructions earlier but was unsuccessful in my attempt. Do i enter "path <location of JDK>"? Does the JDK HAVE to be in a certain place? Is there a way to change the default directory?

//----------------------------------------------------------------------------
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings> <What do I type here to have the the javac work?>
//----------------------------------------------------------------------------
Sorry for being a little dense about this whole subject... Thanks for your patience and help!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
PATH and CLASSPATH are environment variables ...
Right click on My Computer. Choose Properties. Click on the Advanced tab. Click on the Environment Variables button. If you are an administrator on your computer, find PATH (or Path) in the System variables section, highlight it and click on the Edit button. Find where you installed the jdk (by default it probably went into C:\Program Files\java\jdkX.x.x_xx). Add that to your path (preferably at the beginning) -- so you see C:\Program Files\java\jdkX.x.x_xx\bin;<the rest of the pre-existing path>
Keep clicking the OK button until all those windows close.

Open a DOS prompt (find in your start button or click Start -> Run... -> cmd)
Type

echo %PATH%

and check if you see your addition.

Right click on My Computer again... go through the same drill to get to environment variables. You probably don't have CLASSPATH listed there yet, so click the "New" button to add it.

As far as I know, the only way to change the default directory for the jdk is at installation time, but it frequently doesn't matter -- as long as you know where it is.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiling in the cmd prompt
 
Similar Threads
how to execute dos commands using RunTime.getRuntime.exec()
facing jdk installation problem for windows xp
cann't start deployment wizard
How to close the command prompt open by Runtime.exec
Forms&Reports 6i for WindowsNT refused connection to Personal Oracle 8i for Win2000