Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Javac: File Not Found  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote down CLASSPATH and PATH in my system variables already.
The CLASSPATH's value is %classpath%;. And the PATH's value is %path%;C:\Program Files\Java\jdk1.6.0_20\bin

I'm not sure if there are any errors in that above, so I just included it.
After this, created my source file, saved it in C:\Program Files\Java\jdk1.6.0_20\bin as MyFirstApp.java. So I open command prompt, enter: javac MyFirstApp.java

This is what comes up:

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

Help?


 
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

After this, created my source file, saved it in C:\Program Files\Java\jdk1.6.0_20\bin as MyFirstApp.java. So I open command prompt, enter: javac MyFirstApp.java


First of all, saving sources in your JDK installation bin directory is not recommended. you should put put your sources somewhere else, like "C:\Java"

javac: file not found: MyFirstApp.java


javac does not use the CLASSPATH to find the file you pass on the command line. You have to tell it where the file is. In your case, the file is in C:\Program Files\Java\jdk1.6.0_20\bin, so either move to this directory (cd C:\Program Files\Java\jdk1.6.0_20\bin), or compile the class using its full path (javac C:\Program Files\Java\jdk1.6.0_20\bin\MyFirstApp.java)
 
Travis Rademacher
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much. I have another problem. I compiled the source file fine. Now I tried to run the class file. In command prompt, I typed: java c:\java\myfirstapp.class

It gave me a message:
Exception in the thread "main" java.lang.NoClassDefFoundError: c:\java\myfirstapp/class

Caused by: Java.lang.ClassNotFoundException: C:\java\myfirstapp.class
at:

And then a bunch of stuff


This is my source file:

public class MyFirstApp {

public static void main (String[] args) {
System.out.print("JAVA!!!"); }
}


Is it an error in my programming or what?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ClassNotFoundException tells you that the JVM cannot find your class. You need to set the CLASSPATH properly to run java programs. There are different ways to do it, one of them being to use the "-cp" flag on the command line. For example, you can go to C:\java (cd c:\java) and tell the JVM to look for class files in the current directory, like this : java -cp . MyFirstApp. Be careful that class names are case sensitive, and that you don't need to pass the extension (.class).
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use java -classpath <DirectoryOfClass> classname.

Hope this will resolve your problem.
 
Travis Rademacher
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I did was:

java -cp <c:\java> MyFirstApp

It told me access is denied. I am system administrator so this confuses me.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are these brackets for ?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. I guess you left them after seeing the help :


Remove them.
 
Java Cowboy
Sheriff
Posts: 16084
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at Sun's Hello World tutorial, it explains you step by step how to write, compile and run your first Java application and it also describes common problems and solutions.

I see you're not familiar with how the Windows command prompt works. It's a good idea to familiarize yourself with the concepts of the Windows command prompt first, so that it's easier to understand what you're doing and what those commands mean.
 
Travis Rademacher
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you christophe. My code works fine now
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!