This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes javac not making a .class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "javac not making a .class file" Watch "javac not making a .class file" New topic
Author

javac not making a .class file

Desirae Starling
Greenhorn

Joined: Nov 08, 2008
Posts: 3
Hello.

First and foremost - I am a beginning beginner. I'm struggling with even getting HelloWorldApp.java to compile.

I set my path for javac, yet when I run the compiler, nothing happens. No error, no class file created.

What it looks like when I call the compiler -

C:\Users\Dwayne\java>PATH javac HelloWorldApp.java

I then type dir to see if the class file was created - no luck.

I have set my classpath and have used the echo function to check it.

C:\Users\Dwayne\java>echo %classpath%
C:\Users\Dwayne\java

I have Vista as an OS. Can anyone help me? Let me know if you need to know more.
[ November 09, 2008: Message edited by: Desirae Starling ]
Brian Lang
Ranch Hand

Joined: Oct 21, 2008
Posts: 43
Hi Desirae.

You're actually using the command PATH on the command line before javac? AS in

C:\Users\Dwayne\java>PATH javac HelloWorldApp.java

??

This is incorrect. The executable file 'javac.exe' that exists within your JDK installation directory needs to be found within the PATH setting on your machine (to recall it easily that is). It works like this: 'javac.exe', if you installed the JDK to the default directory, should be in C:\Program Files\Java\jdk_VERSION\bin. You should use Windows Explorer to verify this. If that's the case, then the command line has no idea how to find the command "javac" to execute and compile the .java source code file into bytecode. Same thing for the 'java', 'jar' and 'javadoc' commands. The PATH environment variable needs to be altered to include that 'bin' directory so the command line can find it. Otherwise you have to do something like this:

C:\Program Files\Java\jdk_VERSION\bin\javac.exe HelloWorld.java

Do a quick search on Google for "Windows Vista environment variables (PATH|CLASSPATH)". While you're at it, set an environmental variable JAVA_HOME to match your JDK installation directory (the aforementioned "C:\Program Files\Java\jdk_VERSION"

With the CLASSPATH, it should at least be set to '.' (the dot indicates the current working directory). So something like this should be returned when you request the %CLASSPATH% variable:
CLASSPATH=.

Just FYI, when I perform the install on my Win machines, I always install to C:\Java\jdk_VERSION, it just makes things easier in the long run. Then I install all Java related applications or libraries to a subdirectory under C:\Java and everything is in an easy to find place. Another good tip (if you're using JDK v6 as you should be) is to create a C:\Java\JAR directory and add that to your CLASSPATH as well, using C:\Java\JAR\* as a wildcard to any .jar file you store there.
[ November 09, 2008: Message edited by: Brian Lang ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Welcome to JavaRanch

Slight point about the previous post; the PATH entry starts with C:\ (usually) and ends with bin, not javac.exe. It is the name of the directory the executable files are in.
The advice to create a separate directory to hold yoru own files is ver good.
The CLASSPATH need only contain the . which might appear as . .; ;. or ;.;
Brian Lang
Ranch Hand

Joined: Oct 21, 2008
Posts: 43
Thanks for pointing that out, I've edited my post.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Originally posted by Brian Lang:
Thanks for pointing that out, I've edited my post.


Desirae Starling
Greenhorn

Joined: Nov 08, 2008
Posts: 3
Thanks much. I've been reading so much about the CLASSPATH and PATH that it's getting hard to tell what is what. I've never worked with these things before. :/ I thought learning Java would be a challenge. Little did I know that my first roadblock would be understanding how to use the compiler. haha. I'll be back to let you know how it's going.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Once you have worked out how to do it, you can set the PATH correctly in a minute or two, but lots of people really struggle with it. That is why, if you find the problems page in the Java� Tutorials, this is the first problem they describe.
At this stage you only want the . in your CLASSPATH, but the bit about adding a jars folder sounds a good trick for use later on.
Desirae Starling
Greenhorn

Joined: Nov 08, 2008
Posts: 3
Alright, I had the PATH set incorrectly. I thought it was correct because when I typed PATH in the command line I didn't get the usual error. But, all is well now. I thought my problem HAD to be different from everybody elses, so I posted. Sorry.

Thanks for your help!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Nothing to be sorry about; you had a problem and you sought help. We tried to help.

What we are interested in is: Have you got it working?
Richard Cockrum
Greenhorn

Joined: Jun 08, 2009
Posts: 1
Hey I am having the same problem where "javac HelloWorldApp.java" is not printing any errors, but no .class file is being made. I am fairly sure my PATH variable is correct - C:\Program Files\Java\jdk1.6.01_01\bin - but since there isn't any error, I have no clue what is going on. The spelling for the .java file and the installation of the compiler to the indicated folder are both correct. PLEASE HELP!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Welcome to JavaRanch.

Have a look at Sun's Hello World tutorial, which explains in small steps how to write, compile and run your first Java program.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Is there actually a 1.6.01 version of Java? I could only find 1.6.00_14.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javac not making a .class file
 
Similar Threads
-classpath command revisited
problems installing java
creating a file,compiling using javac,
Classpath Problems
classpath problem win2000