Results 1 to 4 of 4

Thread: 10.04 java: could not find main class

  1. #1
    Join Date
    Nov 2005
    Location
    Victoria, B.C.
    Beans
    24
    Distro
    Ubuntu Breezy 5.10

    10.04 java: could not find main class

    Ubuntu 10.04, AMD 64 64 bit edition, Sun-6-Java JDK

    I am trying to start a simple .class file


    ****I am in the directory which contains the class files shown by ls
    frits@frits-inwin:~/GroovySnippets/classes$ ls
    Fibonacci.class Fibonacci$_run_closure1.class
    ****I have a CLASSPATH including the current directory:
    frits@frits-inwin:~/GroovySnippets/classes$ echo $CLASSPATH
    .:/usr/share/groovy/embeddable/groovy-all-1.0.jar
    ****I start java"
    frits@frits-inwin:~/GroovySnippets/classes$ java Fibonacci
    Exception in thread "main" java.lang.NoClassDefFoundError: groovy/lang/Script
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)
    ... 12 more
    Could not find the main class: Fibonacci. Program will exit.
    ****end of terminal contents.
    I set every possible permission on Fibonacci.
    Any ideas, or is this a bug?

  2. #2
    Join Date
    Apr 2006
    Beans
    800
    Distro
    Lubuntu 12.04 Precise Pangolin

    Re: 10.04 java: could not find main class

    Make sure you add the directory in which your compiled program resides to the classpath, too.
    Notice the added dot (=current dir) after the semicolon in classpath:
    Code:
    java -cp $CLASSPATH;. Fibonacci

  3. #3
    Join Date
    Nov 2005
    Location
    Victoria, B.C.
    Beans
    24
    Distro
    Ubuntu Breezy 5.10

    Re: 10.04 java: could not find main class

    Thank you. That runs indeed provided of course that I am executing in that directory.
    However, I thought I could run Fibonacci in any directory, provided the directory that contains the class (~/GroovySnippets/classes in this case) is in the CLASSPATH. My example shows that that does not work contrary to my reading of CLASSPATH. I found using the . directory in th classpath statement to be of the essence.

  4. #4
    Join Date
    Apr 2006
    Beans
    800
    Distro
    Lubuntu 12.04 Precise Pangolin

    Re: 10.04 java: could not find main class

    No problem. Always glad to help a fellow Java coder I think the wikipedia entry on Java Classpath explains it very well: http://en.wikipedia.org/wiki/Classpath_(Java)

    To help others find solutions you might want to tag this thread as SOLVED: http://ubuntuforums.org/showpost.php...51&postcount=6

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •