aspose file tools*
The moose likes Beginning Java and the fly likes setting path and classpath in ms xp pro 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 "setting path and classpath in ms xp pro" Watch "setting path and classpath in ms xp pro" New topic
Author

setting path and classpath in ms xp pro

Jim Strickland
Greenhorn

Joined: Nov 19, 2005
Posts: 15
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.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Lynn DePriest
Greenhorn

Joined: Nov 21, 2005
Posts: 7
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


Lynn DePriest<br /> <br />Imagination bridges the gap between ignorance and understanding!
Jim Strickland
Greenhorn

Joined: Nov 19, 2005
Posts: 15
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting path and classpath in ms xp pro