View Full Version : 10.6 + JAVA = not working?

Nov 5, 2009, 02:50 PM
Okay, it is first time after 10.6 upgrade on 10.5 I used JAVA on this Mac. And it did not work. So I went Sun page for tutotial. Here is the program:
//A Very Simple Example
class ExampleProgram {
public static void main(String[] args){
System.out.println("I'm a Simple Program");

Saved it to "ExampleProgram.java".

javac ExampleProgram.java
java ExampleProgram

Exception in thread "main" java.lang.NoClassDefFoundError: ExampleProgram
Caused by: java.lang.ClassNotFoundException: ExampleProgram
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:319)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
at java.lang.ClassLoader.loadClass(ClassLoader.java:254)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:399)

And it's the same for every JAVA program. What's wrong? Anyone see?

Nov 5, 2009, 03:33 PM
worked fine for me on 10.6. Maybe try:
java -cp . ExampleProgram

to see if . isn't in your default classpath? I can't imagine why that would be.

Also, was ExampleProgram.class generated in your current directory?


Nov 5, 2009, 03:55 PM
Define your class as:

public class ExampleProgram {

It should work without public (and it does work here), but it's not a good idea.

Make sure you don't have a CLASSPATH environment variable defined. Execute this Terminal command:

printenv | sort

Copy and paste the output into a reply post.

Nov 5, 2009, 10:41 PM
a) "public" does not change anything.
b) Yeah, it looks I do have CLASSPATH set to CLASSPATH=/Users/david/.resolver somewhy.
c) java -cp . ExampleProgram works.

Yeah, it's a DocBook thing. Uninstalling DocBook fixed it.