10.6 + JAVA = not working?

Discussion in 'Mac Programming' started by davidlt, Nov 5, 2009.

  1. macrumors member

    Joined:
    May 22, 2007
    Location:
    Lithuania
    #1
    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:
    Code:
    //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".

    When:
    javac ExampleProgram.java
    java ExampleProgram

    Got:
    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?
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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?

    -Lee
     
  3. macrumors 603

    Joined:
    Aug 9, 2009
    #3
    Define your class as:

    Code:
    [B]public[/B] 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:

    Code:
    printenv | sort
    
    Copy and paste the output into a reply post.
     
  4. thread starter macrumors member

    Joined:
    May 22, 2007
    Location:
    Lithuania
    #4
    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.
     

Share This Page