• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

setting path and classpath in ms xp pro

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe, from my rooting around on the internet, that I need to modify Path and add a variable Classpath in my system variable for MS XP pro. That is, if I am going to run the java programs from the cmd prompt.

Strangely enough, I can't find the definitive instructions on the Sun site or the Microsoft site for doing this. I have found some instructions in various places, some which seem old. Some instructions say one missed keystroke and your computer may not boot up again.

I've even looked in some java books in the library, and they don't seem to talk about installing java at all, they assume you have it installed correctly already.

Can anyone explain what I need to do with path and classpath or point me to an explanation that is uptodate?

Thanks.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The PATH variable basically tells Windows where to find the Java installation. This can save you a lot of typing at the Command Prompt, because instead of typing a full path like "C:\Programs\jdk5.0\bin\javac..." (or wherever you installed it), you would only need to type "javac..."

Try these instructions from Sun for setting your PATH variable in Windows...

http://java.sun.com/j2se/1.5.0/install-windows.html#Environment

The CLASSPATH basically tells Java where to find certain packages -- for example, a custom library that you might create or download. There's a lot of discussion about under what circumstances you might want to set this (search the forums for "classpath"). If you're just starting with Java, I recommend not setting the CLASSPATH.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I like to set both PATH and CLASSPATH from the command line right before running the Java program. To avoid repetitive typing, I often make a custom batch file to launch each program. HERE are some tips for getting started and working up to more complex programs.

BTW: This technique lets you keep multiple JRE versions around and set the path to the right one for each program. I can do my work-related stuff on 1.3 and my fun stuff on 5 with no global system variables to confuse things.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take what I'm about to tell you with a grain of salt because I am VERY new to all of this, but I ran into a problem last night with my very first attempt at writing and running a Java app, and the problem had to do with my ClassPath setting. I could compile the .java file into a .class file, but when I would attempt to run the .class file, I would get the following error:

NoClassDefFoundError:

This was because (I think anyway) XP was looking at the location that was being specified in my ClassPath variable for the file that I was trying to run. Initially, thanks to advice I received from SIR Ram, I set my ClassPath=[blank] from the DOS prompt, which allowed my program to run correctly. Then I did a little research and figured out what was going on, so I created a folder to store all of my newly created class files and then added the path to the folder to my existing ClassPath variable. Now everything that I create seems to work fine.

As for how to set this, the article that marc weber provided a link to seems to spell that out pretty well. As for me, I simply right-click on My Computer (desktop) and go to properties. From there, I click on the Advanced tab and then click on the Environment Variables buttom at the bottom of that page. Once the next page appears, I click on the ClassPath line in the System Variables area and then click the edit button at the bottom. From there, I just add a semicolon to whatever is already on the line and add the path to where I create my class files (ex. C:\Java). That's it.

Don't confuse this with setting the Path though. You can get to the place where you set the Path the same way as I described for setting ClassPath, but you'll need to specify the location of the /bin folder instead of where you put your .class files.

Another thing that I did to expedite things along a bit was to create a shortcut to cmd on the desktop and then edited the properties of the shortcut so that the prompt would start in my java folder. It just saves a little time.

Hope this helps.

Lynn
 
Jim Strickland
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All of this has been a great help, but Lynn's was the clearest to me. I think because it came from a beginner to another beginner, and we share the same lack of experience with Java.

I appreciate everyones help. Tis a great bunch of people here.
 
reply
    Bookmark Topic Watch Topic
  • New Topic