• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Compiling in the cmd prompt

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, not official yet ...
Good point.
 
Alex Wood
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic