• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting up CLASSPATH  RSS feed

 
Weston Preecs
Greenhorn
Posts: 5
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When i try to compile a program it gives me this message after i type: C:\windows\system32>javac JavaTest.java i get this error.

javac: file not found: JavaTest.java
Usage: javac <options> <source files>
use -help for a list of possible options

I have my CLASSPATH set to C:\Users\weston\Documents\Java and in that folder is my source called JavaTest.java

If you can tell me what i am doing wrong please tell me because i am very confused.
 
Suraj Bhosale
Greenhorn
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all according to error Compiler is not able to get JavaTest.java file that means you must be compiling from some another directory. Just do one thing where your .java file is located copy that path from explorer address and in command prompt type cd [paste] and hit enter now directory will be changed.and then type javac JavaTest.java command.
 
Weston Preecs
Greenhorn
Posts: 5
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i did exactly as you said and now it pulls up a menu to pick what software to open it with (also im on windows 8).
 
Suraj Bhosale
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Weston Preecs wrote:i did exactly as you said and now it pulls up a menu to pick what software to open it with (also im on windows 8).

Ok Let us assume now you have opened command prompt .In cmd you will see that the directory path will benow just see where is your .java file located on hard disk. Let us assume its in folder so In cmd you have to change the directory so that javac tool will be able to find your .java file. For that you will have to change the directory path. You can do this by typing in cmd the below command and hit enter now your cmd path will be changed from to d:\JavaPrograms. If still you see c:\Users\AccountName then type d: after this you will in cmd prompt now you can type javac TestJava.java command after getting in to the file located directory.
The conclusion is that to run any java file first you have to travel to the file located directory/folder using cd command and afterwards you have to type the javac command.Hope this solves your problem.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Weston, you might want to read a tutorial on using the Windows Command Prompt.
 
Weston Preecs
Greenhorn
Posts: 5
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok now it works fine i dont get any errors or warning and in the file with the .java file i get a .class file with it exept in the cmd prompt i dont get any message should it display text the code is
 
Suraj Bhosale
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Weston Preecs wrote:Ok now it works fine i dont get any errors or warning and in the file with the .java file i get a .class file with it exept in the cmd prompt i dont get any message should it display text the code is


No at compile time you will not get any message on console. Only The java file is loaded into JVM and it checks for any syntax error is there or not. You are getting .class file that means It is compiled successfully.
 
Weston Preecs
Greenhorn
Posts: 5
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok now i get an error when i try to run the class i type d: first then i hit enter then i type java JavaTest.class and i get this error message:



If you can help me with this i would really appreciate it.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of: java TestClass.class, you should type: java TestClass

The java command expects a class name, not a filename.

Have a look at Oracle's Hello World tutorial.
 
Weston Preecs
Greenhorn
Posts: 5
Android Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you it works perfectly now i followed the HelloWorldApp tutorial and it really helped.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!