Simple JAVA class won't run on 10.5?

Discussion in 'Mac Programming' started by c-Row, Jan 2, 2008.

  1. c-Row macrumors 65816

    c-Row

    Joined:
    Jan 10, 2006
    Location:
    Germany
    #1
    I finally picked up my JAVA books again to get into the subject this year, but so far it's been more struggle than fun. I started with the easiest code listing one could imagine.

    Code:
    public class Hello
    {  
      public static void main (String[] args)
      {
         System.out.println("Hello World!");
      }
    }
    It compiles fine (using "javac" in Terminal), but I can neither run the compiled class file in Finder nor via Terminal.

    Even the examples from other websites (O'Reilly etc.) won't show any sign of life, although at least they give me an error message (Jar Launcher: The jar file "YaddaYadda.class" couldn't be launched. Chek the Console for possible error messages). Which isn't much of help at this point.

    What could be wrong?
     
  2. Sayer macrumors 6502a

    Sayer

    Joined:
    Jan 4, 2002
    Location:
    Austin, TX
    #2
    Worked for me:

    Code:
    Jasmine:~ me$ javac Hello.java
    Jasmine:~ me$ java Hello
    Hello World!
    You didn't provide any details on your setup e.g. what OS X version, which Java JDK you installed recently...
     
  3. c-Row thread starter macrumors 65816

    c-Row

    Joined:
    Jan 10, 2006
    Location:
    Germany
    #3
    I'm on 10.5.1 but didn't install any additional files since I thought everything came in-the-box with OS X.
     
  4. ChrisBrightwell macrumors 68020

    ChrisBrightwell

    Joined:
    Apr 5, 2004
    Location:
    Huntsville, AL
    #4
    PEBKAC. :)

    Read the documentation on the "java" command.
     
  5. c-Row thread starter macrumors 65816

    c-Row

    Joined:
    Jan 10, 2006
    Location:
    Germany
    #5
    Why? Oh why? I just tested it once more, and it works fine!

    :confused:

    No idea what caused this in the first place, but now my class greets me as I deserve it. :D Thanks for your efforts!
     
  6. afunsten macrumors newbie

    Joined:
    Feb 6, 2008
    #6
    Works

    If you exclude the .class extension on your class file is works! This is very counter intuitive. _Adam
     

Share This Page