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

Suspected class path problem

Linze marin
Greenhorn

Joined: Jul 23, 2004
Posts: 12
I am a java beginner, attempting to teach myself the lang.
I think that I have a class path problem. My classpath is c:\java

when I write and execute a HelloWorld program in a directory
below c:\java (such as c:\java\test) I actually run the version in c:\java.

What do I need to do to fix this?

Second question: I am a procedural programmer who is struggling to
understand OOP. Can anyone recommend a book to me that helps me gain a better understanding of OOP specifically, and how to use classes and design
program logic using OOP?

Thanks much
Linze
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
Maybe I do not understand you very well, but I do this as follows

compilation
C:\java\test\>javac HelloWorld.java
and running
C:\java\test\>java HelloWorld

it works on current directory.
I think you don't need to setup classpath for such simple program as HelloWorld is. Class path should point to location where are the libraries which your code use.


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Sandeep Jindal
Ranch Hand

Joined: Aug 25, 2003
Posts: 180
Hi,

You can read the book "Thinking in Java" by Bruce Ecel. This book is for begineers, and in general an excelent book to start with.

Regards
Sandeep Jindal
Linze marin
Greenhorn

Joined: Jul 23, 2004
Posts: 12
This is precisly what I would like to have happen:

compilation
C:\java\test\>javac HelloWorld.java
and running
C:\java\test\>java HelloWorld

This is what is actually happening:
compilation
c:\java\test\>javac HelloWorld.java
and running a DIFFERENT VERSION found on:
c:\java

I know this, because the actual text printed out is unique in each version of the HelloWorld program.

Linze
Adrian Marti
Greenhorn

Joined: Sep 07, 2004
Posts: 11
If u put . in ur classpath it will look for class files in the current directory so for example classpath=c:\java;.;

That should work i think.

Adrian
Linze marin
Greenhorn

Joined: Jul 23, 2004
Posts: 12
Sorry to be a bother,

I just set up the classpath to read:
c:\java;.;
(ending with: Semicolon dot Semicolon)

I then rebooted, and ran HelloWorld in c:\java\test
again, and the version in c:\java ran.

I am running this on a fairly new Dell D600 laptop,
running windows 2000.
I welcome any help and advice.
Thanks again, Linze
[ September 17, 2004: Message edited by: Linze marin ]
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Of course.
The jvm searches the classpath for a HelloWorld.class and starts in C:\java.
Bingo - there is a HelloWorld.class!
It doesn't look further into your . dir, because it already found what it was searching for.

Rebooting your computer?
Even on windows you don't need to.
Redefine the classpath, and reopen a shell.
echo %CLASSPATH% and verify that it has changed.

For this atomic issue, you would set it to:

So it will look into the actual directory first.

I guess unsetting the classpath at all will be sufficient to run programs in the actual directory.

You may (un-)set the classpath temporary with:

but if you close your shell, it's lost.


http://home.arcor.de/hirnstrom/bewerbung
Linze marin
Greenhorn

Joined: Jul 23, 2004
Posts: 12
Thank you. It sure seems obvious now that
you describe is so well.

Thanks, Linze
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Suspected class path problem