Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Very Basic doubt about CLASSPATH Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Very Basic doubt about CLASSPATH" Watch "Very Basic doubt about CLASSPATH" New topic
Author

Very Basic doubt about CLASSPATH

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Hi all,

First it was package problems....

I just installed Win2k at home, and I have a problem with my Java installation.

Using textpad, I write the following very simple program, many of you have probably seen it before!This compiles wonderfully, but will not run. Here is what I get from both Textpad's Ctrl-2, and directly from a console window:
My very basic doubt, which I suppose could be answered by trying it out, is this: I don't currently have an environment variable called CLASSPATH. Do I need one, if I do, what should it say, and why do I need one?

If this is not the problem, then what could possibly be wrong?

The reason I even knew I had this problem was that I tried to install a library of classes from Infragistics and the install program (which was an exe) couldn't find either of two Java Runtimes, and when I pointed them right at java.exe, it said "This does not appear to be a valid java runtime". I tried java.exe under the jre and then I decided to download the class file version of the same download... and it had the same "Exception in thread main..." error. So I tried the simplest thing I knew how.. hello world, and it doesn't work either.

Any ideas? p.s. I compiled and ran a few things a few days ago and the only thing different since then is I upgraded my IDE controller BIOS - think that has anything to do with it?
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,maybe this can help you.
Just add these on your autoexec.bat or write a new bat file with these lines and run it.(I installed jdk on "E:\jdk",you can replace it wiht your dirctory.):
SET JAVA_HOME=E:\JDK
SET PATH=E:\JDK\BIN
SET CLASSPATH=E:\JDK\LIB\TOOLS.JAR;E:\JDK\LIB\DT.JAR
Good luck
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I'm using Win2k, no such thing as autoexec.bat

JAVA_HOME is already set to c:\jdk1.3.1
PATH doesn't seem to be necessary, because from any directory, I can find both java.exe and javac.exe
and if I know my CLASSPATH correctly, which was my basic doubt... I don't need to explicity add tools.jar or dt.jar, do I?
John Lennon
Greenhorn

Joined: Jun 14, 2001
Posts: 3
I try it just now and I found you are right.It is not necessary.Just add your classpath and it will work.You can right click "my computer" to choice "properties",click "advance-->environment-->setting",and you will find "classpath" there.Edit it,add the directory your class be in.Login again and it will be OK.
Or just simply write a bat file like that(env.bat):
-----------------------------------
SET JAVA_HOME=E:\JDK
SET PATH=E:\JDK\BIN
SET CLASSPATH=E:\JDK\LIB\TOOLS.JAR;E:\JDK\LIB\DT.JAR;E:\myjava
------------------------------------
Once you run java,you run this bat file first.
It really work.
Luck.
[This message has been edited by John Lennon (edited July 05, 2001).]
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
Hi!
Well in the command line where you run the Program using Java <program name>
type first "set classpath=%classpath%;.;"
then type "java <program name>"
It will work..
Regds
Gautham Kasinath


"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at : http://www.geocities.com/gkasinath
gautham kasinath
Ranch Hand

Joined: Dec 01, 2000
Posts: 583
well the line : set classpath=%classpath%;.; sets the classpath to the current dirctory as well..
notice the "."
Regds
Gautham Kasinath
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Hi guys, thanks for your help.

I'm at work now, so can't try out anything.

I guess my basic doubt boils down to: I thought the java runtime was smart enough to look in '.' without my having to add it to CLASSPATH.

I don't currently have a CLASSPATH entry at all, and p.s. You don't need to re-login on winNT or win2k. You just can't reuse an old Console window. Once you open a new Console, it has the new settings.
 
wood burning stoves
 
subject: Very Basic doubt about CLASSPATH
 
Similar Threads
nosuchmethoderror
Something is wrong with my Java on LInux...
Compiling, but not running !!!
execute java on linux
WHy does main() work with private accessibility?