On java program running on ubuntu

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sasimca007
    New Member
    • Sep 2007
    • 129

    On java program running on ubuntu

    Hello friends,
    I installed java with the following command:
    sudo apt-get update
    synaptic
    In synaptic i searched for sun-java6-jdk and marked and applied.

    After that i wrote a program and complied with javac /java/Hello.java it showed no errors and i run the program with java /java/Hello.java and it shows the follwing errors

    Exception in thread "main" java.lang.NoCla ssDefFoundError : java/Hello.java
    at gnu.java.lang.M ainThread.run(l ibgcj.so.7)
    Caused by: java.lang.Class NotFoundExcepti on: java/Hello.java
    at java.lang.Class .forName(libgcj .so.7)
    at gnu.java.lang.M ainThread.run(l ibgcj.so.7)

    I think it is for not setting classpath and anybody helps me for setting classpath How to set classpath? and where to set classpath? in ubuntu
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Don't try to run the source file Hello.java, simply run the Hello class file. (no .class
    extension used, the VM figures it out).
    You do have to compile your source file Hello.java though.

    kind regards,

    Jos

    Comment

    • sasimca007
      New Member
      • Sep 2007
      • 129

      #3
      Hello friend,
      After running class file also i am getting the following error:

      Exception in thread "main" java.lang.NoCla ssDefFoundError : Hello.class
      at gnu.java.lang.M ainThread.run(l ibgcj.so.7)
      Caused by: java.lang.Class NotFoundExcepti on: Hello.class not found in gnu.gcj.runtime .SystemClassLoa der{urls=[file:./], parent=gnu.gcj. runtime.Extensi onClassLoader{u rls=[], parent=null}}
      at java.net.URLCla ssLoader.findCl ass(libgcj.so.7 )
      at java.lang.Class Loader.loadClas s(libgcj.so.7)
      at java.lang.Class Loader.loadClas s(libgcj.so.7)
      at java.lang.Class .forName(libgcj .so.7)
      at gnu.java.lang.M ainThread.run(l ibgcj.so.7)

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Go to the directrory where your compiled Hello.class file is stored. Type this:

        Code:
        java -cp . Hello
        This tells the VM (java) to look for classes in the current directory (the dot).

        kind regards,

        Jos

        Comment

        • satch
          New Member
          • Feb 2008
          • 23

          #5
          Originally posted by JosAH
          Go to the directrory where your compiled Hello.class file is stored. Type this:

          Code:
          java -cp . Hello
          This tells the VM (java) to look for classes in the current directory (the dot).

          kind regards,

          Jos
          Alternatively you can add the path to the directory, where the compiled Hello.class is created, to the CLASSPATH environment variable(though -cp option is the preferred approach).
          For details on java classpath read the following link :
          http://java.sun.com/j2se/1.4.2/docs/tooldocs/solaris/classpath.html

          Comment

          Working...