File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How do I change the path environment? 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 "How do I change the path environment?" Watch "How do I change the path environment?" New topic
Author

How do I change the path environment?

Andy G
Greenhorn

Joined: Aug 21, 2005
Posts: 4
Hi - I'm a newbie using the Head First Java book. I've been trying to follow the instructions on the book on how to change the path, but they are not very helpful. Someone else posted the same question and I tried that, but it didn't work either.

I am using XP home edition. I downloaded the J2SDK from Sun�s website. I created a new folder on my desktop called java and saved the following code with .java extension:

public class MyFirstApp{

public static void main (String[] args){
System.out.println("I Rule!");
System.out.println("The World");
}

}

How do change the path and get it to compile? Please help!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You can change it permanently in Start / Settings / Control Panel / System / Advanced / Environment Variables.

I have a bunch of different JREs installed and don't dare mess with permanent stuff because it might mess up my work life, so I prefer to set the path right before starting the program. I have batch files like:

Once that gets going, your next question is likely to be about classpath. The answer is the same right before the Java command:


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
Andy G
Greenhorn

Joined: Aug 21, 2005
Posts: 4
I went to Start / Settings / Control Panel / System / Advanced / Environment Variables and added "C:\Program Files\Java\jdk1.5.0_04\bin" Is there anything else I should do?
samdeep aarzoo
Ranch Hand

Joined: Jun 09, 2005
Posts: 160
set classpath some.jar;%classpath%

instead of this if i use than

set classpath some.jar;.
is it correct
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Adding the bin dir to the path will make it so you can open a command window and type "java" or "javac" and those programs will run. That's a critical step for sure.

When you run your program it might say it cannot find classes that you imported from various places. That means the compiler knew the classpath to those classes and the runtime did not. If and when this happens, you'll need to add the path to those classes to your classpath.

I showed "set classpath = some.jar;%classpath%" because the classpath might already have some good things in it. This puts my new things in the front but preserves anything already there. If I have to add several things to the classpath I just have more commands in that format.

You could set up classpath permanently as well, but it's really something that changes depending on the program you're running, so it makes more sense to set it up every time you run.
Phil Dixon
Greenhorn

Joined: Aug 13, 2005
Posts: 11
Andy,

I'm working my way through HFJ aswell. I added two lines to autoexec.bat

autoexec.bat

This worked for me although this is only my second week as a would be Java programmer.
Andy G
Greenhorn

Joined: Aug 21, 2005
Posts: 4
Thanks for all the help guys!

But know everytime I try to run the class i get the following error:

Exception in tread "main" java.lang.NoClassDefFoundError

I am trying to run:

public class MyFirstApp{

public static void main (String[] args){
System.out.println("I Rule!");
System.out.println("The World");
}

}
Andy G
Greenhorn

Joined: Aug 21, 2005
Posts: 4
This is the error i am getting:

 
 
subject: How do I change the path environment?