• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot find [filename].java

 
Rekha Anand
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.

I have JDK1.3 installed on my system. Obviously, the JVM is in c:\jdk1.3\bin folder. Any .java file created in the bin folder runs fine. But if i save my .java source code in some other folder say c:\jdk1.3\bin\prog\abc.java and try to compile it, I get an error "File cannot be found". Please help me.
 
Dhaval Shah
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please execute this command on the command prompt -
> set classpath=%classpath%;c:\jdk1.3\bin\prog

As a result when you run the program the compile would be able to find the file that needs to be executed
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, do not put your own .java or .class files in the JDK's bin directory. This is for Java's "inner workings," and mixing your own files in there is bound to complicate things.

If there is no CLASSPATH specified, Java's default (since version 1.2) is to look in the current directory. So it sounds like you have a system CLASSPATH set (so you're not getting the default behavior) and the set CLASSPATH does not include a dot (.) to indicate the current directory.

The best approach is to avoid a system CLASSPATH entirely. But if you must set one, be sure it includes a dot.

See Java 1.3 Installation Instructions - Classpath for more details.
[ February 26, 2008: Message edited by: marc weber ]
 
Rekha Anand
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much!!

I tried >set classpath=%classpath%;c:\jdk1.3\bin\rekha progs
but still javac cannot find my file !!


Regards
Rekha

P.S. rekha progs is the folder containing my java source code files.
[ February 27, 2008: Message edited by: Rekha Anand ]
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When compiling, first change your current directory to the directory that contains the source file...

C:\>cd jdk1.3\bin\rekha progs

Then compile from that directory...

C:\jdk1.3\bin\rekha progs>javac abc.java

After it's compiled (when you get a new prompt with no error messages), then try running with...

C:\jdk1.3\bin\rekha progs>java abc

If this fails with a "no class definition found" error, then try specifying the current directory (.) as a classpath...

C:\jdk1.3\bin\rekha progs>java -cp . abc

Let us know how this works.
[ February 27, 2008: Message edited by: marc weber ]
 
Rekha Anand
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your help!!

I tried the following:
C:\>jdk1.3\bin\rekha progs\javac abc.java

But I still got an error. This time it says - 'javac' is not recognised as an internal or external command.

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carefully re-read marc's post. In particular note the difference between


and


It seems you missed the step

 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rekha Anand:
...it says - 'javac' is not recognised as an internal or external command...

That suggests that you haven't updated your PATH variable. See step 4 of Sun's Java installation instructions.

After that, please note Ulf's post above.
 
Rekha Anand
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my previous post, I placed the > symbol at the wrong place. Sorry about that. I very well understand that I had to CD first. What I meant to write was
c:\jdk1.3\bin\rekha progs>javac abc.java

This command gave me the error 'javac' cannot be recognized as an internal or external command.

I would like to mention that I have set the path and the classpath to
path=%path%;c:\jdk1.3\bin\rekha progs

and classpath=%classpath%;c:\jdk1.3\bin\rekha progs

but still i am not able to compile the source code from rekha progs folder.

I am sorry that the problem is stretching..

Regards
Rekha
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rekha Anand:
...I would like to mention that I have set the path and the classpath to
path=%path%;c:\jdk1.3\bin\rekha progs

and classpath=%classpath%;c:\jdk1.3\bin\rekha progs...

The PATH should point to...

C:\jdk1.3\bin

...because that's where the executable tools are (like javac and java). It should not point to the "rekha progs" directory. See Update the PATH variable in the installation instructions.

A system CLASSPATH should not be needed at all, because Java's default is to look in the current directory. If you do need a system CLASSPATH (and again, you probably do not need this), then make sure it includes a dot (.) so that class files can be found in the current directory. See Check the CLASSPATH variable in the installation instructions.
 
Rekha Anand
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally... I got it. I want to thank all forum members who helped me on this.

Regards
Rekha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic