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 Command Prompt error- Can't run through compiler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Command Prompt error- Can Watch "Command Prompt error- Can New topic
Author

Command Prompt error- Can't run through compiler

Zach Williams
Greenhorn

Joined: Nov 07, 2010
Posts: 9
Hi guys, I literally just picked up the book last night to start learning Java. I am using Head First Java 2nd Edition. Part of the first chapter has me writing some simple coding.

However, I am having trouble getting the compiler to work. First off, it wont recognize any commands when I use javac. It only recognizes commands that begin with java, like "java -version"

But when I attempt to run this through the compiler using this command.

>java MyFirstApp.java

I get this error from command prompt (see attached)




[Thumbnail for java help.png]

Bobby Smallman
Ranch Hand

Joined: Sep 09, 2010
Posts: 107
Looks like a classpath issue, make sure your classpaths are set correctly, if you did them manually it is pretty easy to miss a typo the first type you do it.


Everyday in every way, we get a little better.
Zach Williams
Greenhorn

Joined: Nov 07, 2010
Posts: 9
Can it still be a classpath issue if I am able to issue the command "java -version" and it is able to display the correct version? I copied the path directly from the location of the /bin file so i dont think I have any typo's
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4664
    
    5

1. No, it's not a CLASSPATH issue at all. It's a PATH issue.
2. You don't run a java source code file with java.exe. It has to be compiled with javac.exe.

Recommended reading:
http://download.oracle.com/javase/tutorial/getStarted/problems/index.html


luck, db
There are no new questions, but there may be new answers.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19064
    
  40

Zach Williams wrote:
But when I attempt to run this through the compiler using this command.

>java MyFirstApp.java

I get this error from command prompt


The JVM (java command) takes the name of the class to run. In this case, you are trying to run the "java" class, in the "MyFirstApp" package. Perhaps you meant...

> java MyFirstApp

Or if you are trying to compile, then you probably mean...

> javac MyFirstApp.java

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Zach Williams
Greenhorn

Joined: Nov 07, 2010
Posts: 9
my path is defined as

C:\Program Files (x86)\Java\jre6\bin

the location of my bin is

C:\Program Files (x86)\Java\jre6\bin

Javac is still coming up as not recognized as internal or external command...
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19064
    
  40

Zach Williams wrote:my path is defined as

C:\Program Files (x86)\Java\jre6\bin

the location of my bin is

C:\Program Files (x86)\Java\jre6\bin

Javac is still coming up as not recognized as internal or external command...


javac is not recognized because you never install the compiler. The JRE is only the runtime environment -- it doesn't include the compiler. See if you have a JDK installed, and if not, install one.

Henry
Zach Williams
Greenhorn

Joined: Nov 07, 2010
Posts: 9
great, thanks for your help!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Command Prompt error- Can't run through compiler