aspose file tools*
The moose likes Beginning Java and the fly likes Environment variables 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 "Environment variables " Watch "Environment variables " New topic
Author

Environment variables

Thomas Cook
Greenhorn

Joined: Jul 16, 2008
Posts: 2
I could really use some help if someone knows how to do this. I have installed jdk1.6.0 on my laptop. The path is set to: C:\Program Files\Java\jdk1.60\bin\;. I also have the ClassPath set to the same setting. When I try to compile a program I get the following error:
"javac: filenot found:program name.java
usage: javac<options><sourcefiles>
use -help for a list of possible options.
Thanks.
Tom.




[edit]Disable smilies. CR[/edit]
[ July 17, 2008: Message edited by: Campbell Ritchie ]
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

"javac: filenot found rogram name.java
usage: javac<options><sourcefiles>
use -help for a list of possible options.


seems like you are trying to compile the .java file "name", in wrong directory ! Where you saved that file (name.java) , Go to that directory and run this command :

<blockquote>code:
<pre name="code" class="core">javac name.java [ENTER]</pre>
</blockquote>

try this,


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Hello, and welcome to the ranch,

As Sagar points out, the "file not found" message tells us that the problem is that the compiler (i.e. javac) is not finding your java file. But first. there is some house keeping to do with your CLASSPATH environment variable. Remove the "C:\Program Files\Java\jdk1.60\bin\" from your CLASSPATH environment variable. (And change the name of it to all upper case if it is not). You don't need (or want) the java bin directory in your classpath. Keep the "C:\Program Files\Java\jdk1.60\bin\" in your PATH. Set your CLASSPATH environment variable to "." (Just a period without the quotes.) The period means the current directory. While not explicitly needed, it is often very helpful, especially when one class you are compiling is dependent on another class in the same directory.

To compile your file...
Let's say the java file 'MyJavaClass.java' is located at "C:\projects\src\MyJavaClass.java". And I want to compile it. We need to change directory to the same directory as the java file (assuming your class is not in a package)and then compile it:
<blockquote>code:
<pre name="code" class="core">
C:\> cd \projects\src
C:\projects\src> javac MyJavaClass.java
</pre>
</blockquote>

Alternatively, if you don't want to change directory to the directory that has your java file in it, you can specify the full path to where your file is:
<blockquote>code:
<pre name="code" class="core">
C:\> javac C:\projects\src\MyJavaClass.java
</pre>
</blockquote>

If you have other class in that directory that MyJavaClass depends on, you need to have that i your classpath; this can be done at the command line:
<blockquote>code:
<pre name="code" class="core">
C:\> javac -classpath "C:\projects\src\" C:\projects\src\MyJavaClass.java
</pre>
</blockquote>

Give that a try. If you are still having problems, let us know.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

Do not set the CLASSPATH to the bin directory of your JDK installation. CLASSPATH is used by Java to search for Java class files, and there are no Java class files in the bin directory of your JDK.

On Java 5 and newer, it's best to leave CLASSPATH unset (don't define a CLASSPATH environment variable). If you do that, Java will automatically look in the current directory for class files.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Thomas Cook
Greenhorn

Joined: Jul 16, 2008
Posts: 2
Thanks Guys this worked. You guys are life savers.
Tom.
 
wood burning stoves
 
subject: Environment variables