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 Problem with  Vista Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with  Vista" Watch "Problem with  Vista" New topic
Author

Problem with Vista

atul vermaa
Greenhorn

Joined: Oct 15, 2008
Posts: 5
hey folks. i am a beginner in Java. i have vista os.. please help me out to set class path environment. i have tried this umpteen time but coudnt make it.
one more favor i need. i have made folder name Java_Prog in D: drive and JDK is installed in C: drive. I write a program in Notepad and save it to Java_Prog folder with .java ext. and on command prompt when i try to compile my .java file then it come up with an error like "class not found exception error."
Please help me out so as i could commence coding.
Thanks a Ton in Advance.
Saurabh V Vakil
Greenhorn

Joined: Jan 30, 2008
Posts: 14
Originally posted by atul vermaa:
hey folks. i am a beginner in Java. i have vista os.. please help me out to set class path environment. i have tried this umpteen time but coudnt make it.
one more favor i need. i have made folder name Java_Prog in D: drive and JDK is installed in C: drive. I write a program in Notepad and save it to Java_Prog folder with .java ext. and on command prompt when i try to compile my .java file then it come up with an error like "class not found exception error."
Please help me out so as i could commence coding.
Thanks a Ton in Advance.



Before compiling the programs, enter the following :
d:\Java_Prog>set path=JDK installation directory\bin

For example if your JDK installation directory is C:\JDK1.5, then enter
set path=c:\jdk1.5\bin
then compile your program.

The only problem with this method is you have to enter the set path.... command every time you open the command prompt. So a better way is to add the classpath to the Path variable in the Environment Variables.
[ October 22, 2008: Message edited by: Saurabh Vakil ]
atul vermaa
Greenhorn

Joined: Oct 15, 2008
Posts: 5
Thanks Buddy. i did it as you said. now my file is compiled successfully but it is not running and giving me output.
it is showing this error: Exception in thread "main" java.lang.NoClassDefFoundEroor :Hello (Hello is my source code file name)

Thanks a Ton.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1527
did you check the directory after compilation, if the .class file exists?


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Saurabh V Vakil
Greenhorn

Joined: Jan 30, 2008
Posts: 14
Originally posted by atul vermaa:
Thanks Buddy. i did it as you said. now my file is compiled successfully but it is not running and giving me output.
it is showing this error: Exception in thread "main" java.lang.NoClassDefFoundEroor :Hello (Hello is my source code file name)

Thanks a Ton.


After compiling the file, enter set classpath=.;
Then tr and run the file.
atul vermaa
Greenhorn

Joined: Oct 15, 2008
Posts: 5
@ Akhilesh
yes .class file exist here.

@ sourabh.
Sir i show you the whole scenario.
there are two option showing in environment variable window
1.user variable and
2.System variable
i have add variable name->path
and variable value ->(C:\Program Files\Java\jdk1.5.0_10\bin)
now
As i my folder(dir) is named as Java_prog in D: drive.
i note down java code:
class Hello
{
public static void main(String arg[])
{
System.out.println("Hello");
}
}
and file name is Hello.java saved in Java_prog in D:
now in cmd i have given command viz
D:\Java_prog>javac Hello.java
( successfully compiled)
D:\Java_prog> java Hello
Exception in thread "main" java.lang.NoClassDefFoundError: Hello
...............
now as you advised i did like this
D:\Java_prog>set path=C:\Program Files\Java\jdk1.5.0_10\bin
D:\Java_prog> java hello
Exception in thread "main" java.lang.NoClassDefFoundError: Hello
it is showing the same problem.
.....................
Thanks a Ton in advance.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3556
    
  15
Originally posted by atul vermaa:
[QBnow as you advised i did like this
D:\Java_prog>set path=C:\Program Files\Java\jdk1.5.0_10\bin
D:\Java_prog> java hello
[/QB]


Before banging your head too hard, I suggest you re-read Saurabh's post. He suggested you set the classpath, not the path.
Alternatively you can try
java -cp . Hello


Joanne
atul vermaa
Greenhorn

Joined: Oct 15, 2008
Posts: 5
i succeed
Thanks a Ton...
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by atul vermaa:
...please help me out to set class path environment. i have tried this umpteen time but coudnt make it...

If it worked with...

java -cp . Hello

...this means that you have set a system CLASSPATH that does not include a dot (.) for the current directory. You probably do not need any system CLASSPATH at all. If you added this as a new variable when installing Java, then remove it. If you must have one (if it was there before and contains other values), then it should include a dot as the first item...

CLASSPATH=.;other_stuff_if_necessary;...

Note that CLASS and CLASSPATH are entirely different things. You will find plenty of bad advice on the internet regarding CLASSPATH, which is probably why you have one set now.
[ October 22, 2008: Message edited by: marc weber ]

"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
atul vermaa
Greenhorn

Joined: Oct 15, 2008
Posts: 5
Note that CLASS and CLASSPATH are entirely different things. You will find plenty of bad advice on the internet regarding CLASSPATH, which is probably why you have one set now.


thanks buddy.
i need one more fevor.
wht is the difference between Classpath and path variable. and how to set them while installing a fresh JDK.
Thnaks a Ton in Advance.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38865
    
  23
Once you have got CLASSPATH set up (it needs a . or ;. or .; or ;.; on Windows, and doesn't need anything on Linux) you never need change it.
When the java tool runs, it looks in the CLASSPATH for classes, images, etc.

The PATH ought to be set up for every installation; it tells the operating system where to find the "java" program.

Do a search through the beginner's forum; this question comes up at least once a week.
[ October 23, 2008: Message edited by: Campbell Ritchie ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with Vista