aspose file tools*
The moose likes Beginning Java and the fly likes the compilers not computing man! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "the compilers not computing man!" Watch "the compilers not computing man!" New topic
Author

the compilers not computing man!

Marcus Deviln
Ranch Hand

Joined: Jan 29, 2009
Posts: 39
I keep getting this miserable noclassDefFoundError when i run from cmd.exe which of course means the OS can't find the compiler right? When I look in the 'c:\Program Files\java\jdk1.6\bin' folder I don't see any file or folder named 'javac'. Where is the compiler?...and do I need to edit or add any environment variables? Could that be a possible culprit? I know about compiling the source files first to produce the .class files but it always says: 'javac' is not an internal or externally recognized command...


+Deviln+ The power of JAVA compels you!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Marcus Deviln wrote:...do I need to edit or add any environment variables? Could that be a possible culprit? ...

Indeed. See step 4 of Java 6 JDK installation instructions for Windows (32 bit). Updating your PATH variable will allow your system to find the java compiler regardless of your current directory.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Marcus Deviln wrote:... When I look in the 'c:\Program Files\java\jdk1.6\bin' folder I don't see any file or folder named 'javac'...

Hmmm, there should be a javac.exe file under that directory.

Presumably, this is where you're telling your system to look by updating your PATH variable. So if the compiler isn't there, updating the PATH won't do it.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13875
    
  10

Marcus Deviln wrote:I keep getting this miserable noclassDefFoundError when i run from cmd.exe which of course means the OS can't find the compiler right?

No, a NoClassDefFoundError does not mean that the OS cannot find the compiler. It means that the Java runtime environment cannot find a Java *.class file that's needed to run a Java program.

Marcus Deviln wrote:When I look in the 'c:\Program Files\java\jdk1.6\bin' folder I don't see any file or folder named 'javac'. Where is the compiler?

That's odd; there should be a javac.exe in the bin folder of the JDK. If it isn't there, then your JDK installation most likely got corrupted somehow; try re-installing the JDK.

Marcus Deviln wrote:...and do I need to edit or add any environment variables? Could that be a possible culprit? I know about compiling the source files first to produce the .class files but it always says: 'javac' is not an internal or externally recognized command...

You have to add the bin directory of the JDK to the PATH, as the JDK installation instructions tell you (see marc's link above).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Marcus Deviln
Ranch Hand

Joined: Jan 29, 2009
Posts: 39
Hello folks! Just a little update here on the above mentioned problem. I managed to get my source file compiled. how do I know? I see the ".class" file next to the ".java" file in the jdk1.6.0_20 folder. I set the environment variables for user and system as follows: PATH and c:\Java\jdk1.6.0_20\bin for the value. That step preceded successful compilation. By the way I was able to get this far because taking the advice I was given I re-downloaded the jdk and sure enough the compiler was present. When I try to use the java command it's that same block of exceptions" exception in main thread..." I also read and re-read the installation instructions from the jdk and I feel like I've tried everything that my tiny little mind can come up with. In other words I'm out of ideas so any advice would be greatly appreciated.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18117
    
  39

Marcus Deviln wrote:When I try to use the java command it's that same block of exceptions" exception in main thread..."



Well, it might help us if you tell us what the "block of exceptions" is... Maybe cut and paste the output on the screen to here.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Marcus Deviln
Ranch Hand

Joined: Jan 29, 2009
Posts: 39
10-4 Henry sorry 'bout the omission

c:\Java>java Child.java
Exception in thread "main" java.lang.NoClassDefFoundError: Child
Caused by: java.lang.ClassNotFoundException: Child.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:202
at java.security.AccessController.doPrivileged(Native Me
at java.net.URLClassLoader.findClass(URLClassLoader.java
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.j
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Child.java. Program will exit.
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Try:
java Child

You compile Child.java to produce Child.class and run the Child.class (but you don't specify .class when running it)
Marcus Deviln
Ranch Hand

Joined: Jan 29, 2009
Posts: 39
check this out:



C:\Windows\System32>java Child
Error: could not open `C:\Program Files\Java\jre6\lib\i386\jvm.cfg'
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1613
    
  10

Marcus Deviln wrote:
c:\Java>java Child.java
Exception in thread "main" java.lang.NoClassDefFoundError: Child
Caused by: java.lang.ClassNotFoundException: Child.java
at java.net.URLClassLoader$1.run(URLClassLoader.java:202
at java.security.AccessController.doPrivileged(Native Me
at java.net.URLClassLoader.findClass(URLClassLoader.java
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.j
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Child.java. Program will exit.


You need to do this first:
javac Child.java

And THEN (upon successful compilation)
java Child

if the first command results in windows saying invalid command (or whatever), you'll need to check your PATH in the system attributes.


When you do things right, people won't be sure you've done anything at all.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1613
    
  10

Marcus Deviln wrote:check this out:



C:\Windows\System32>java Child
Error: could not open `C:\Program Files\Java\jre6\lib\i386\jvm.cfg'


Why are you compiling/running from the system32 folder?? Make a folder specifically for your programs and then compile/run from there.

As for could not open jvm.cfg, do you have a different version of JVM for the version of JDK you are using?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10916
    
  12

run these two commands, and tell us the results:

java -version
javac -version

you should get something like this:


C:\>java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

C:\>javac -version
javac 1.6.0_20

C:\>

This will tell us if your compiler and run-time are in sync.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Marcus Deviln
Ranch Hand

Joined: Jan 29, 2009
Posts: 39
C:\Windows\System32>java -version
Error: could not open `C:\Program Files\Java\jre6\lib\i386\jvm.cfg'

C:\Windows\System32>javac -version
javac 1.6.0_20

C:\Windows\System32>java -version
Error: could not open `C:\Program Files\Java\jre6\lib\i386\jvm.cfg'
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Marcus Deviln wrote:...Error: could not open `C:\Program Files\Java\jre6\lib\i386\jvm.cfg'...

Does that file exist (in that exact location)?
Marcus Deviln
Ranch Hand

Joined: Jan 29, 2009
Posts: 39
Does 'jvm.cfg' exist in that exact location? the answer is no, it exists at c:\Java\jre6\lib\i386
Marcus Deviln
Ranch Hand

Joined: Jan 29, 2009
Posts: 39
I moved the Java folder into the Program Files directory and when I type: java -version...

c:\Program Files\Java>javac Child.java
javac: file not found: Child.java
Usage: javac <options> <source files>
use -help for a list of possible options

c:\Program Files\Java>javac -version
javac 1.6.0_20

c:\Program Files\Java>java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

c:\Program Files\Java>

...so now the java version is showing up
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1613
    
  10

Marcus Deviln wrote:I moved the Java folder into the Program Files directory and when I type: java -version...

c:\Program Files\Java>javac Child.java
javac: file not found: Child.java
Usage: javac <options> <source files>
use -help for a list of possible options

c:\Program Files\Java>javac -version
javac 1.6.0_20

c:\Program Files\Java>java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)

c:\Program Files\Java>

...so now the java version is showing up


so now you need to navigate to the directory where you saved Child.java and try again!

If you use notepad++ there's an option in the run... menu that will open the cmd prompt in the folder the file is located.
Marcus Deviln
Ranch Hand

Joined: Jan 29, 2009
Posts: 39
C:\Windows\System32>cd c:\Program Files\Java\jdk1.6.0_20

c:\Program Files\Java\jdk1.6.0_20>java Child
Variable x is 9



OK great one step taken with several miles to go lovely...
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1613
    
  10

Create yourself a folder for the java files you write... keep your stuff out of the jdk folder and the system32 folder and everything else.

Great Job!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: the compilers not computing man!
 
Similar Threads
Abstract class and interfaces.
compiler advice?
Error: Could not find or load main class com.sun.tools.javac.Main
javac Problems
JAVA_HOME variable