Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: javac: could not find main class

  1. #1
    Join Date
    Aug 2006
    Beans
    458
    Distro
    Ubuntu 12.04 Precise Pangolin

    javac: could not find main class

    I think it's pretty self-explanatory. I'm unable to compile Java programs. Kindly help.

    Code:
    navneeth@ubuntu:~$ java -version
    java version "1.6.0_13"
    Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
    Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)
    navneeth@ubuntu:~$ java
    Usage: java [-options] class [args...]
               (to execute a class)
       or  java [-options] -jar jarfile [args...]
               (to execute a jar file)
    
    where options include:
        -d32          use a 32-bit data model if available
    
        -d64          use a 64-bit data model if available
        -client	  to select the "client" VM
        -server	  to select the "server" VM
        -hotspot	  is a synonym for the "client" VM  [deprecated]
                      The default VM is client.
                      
        -cp <class search path of directories and zip/jar files>
        -classpath <class search path of directories and zip/jar files>
                      A : separated list of directories, JAR archives,
                      and ZIP archives to search for class files.
        -D<name>=<value>
                      set a system property
        -verbose[:class|gc|jni]
                      enable verbose output
        -version      print product version and exit
        -version:<value>
                      require the specified version to run
        -showversion  print product version and continue
        -jre-restrict-search | -jre-no-restrict-search
                      include/exclude user private JREs in the version search
        -? -help      print this help message
        -X            print help on non-standard options
        -ea[:<packagename>...|:<classname>]
        -enableassertions[:<packagename>...|:<classname>]
                      enable assertions
        -da[:<packagename>...|:<classname>]
        -disableassertions[:<packagename>...|:<classname>]
                      disable assertions
        -esa | -enablesystemassertions
                      enable system assertions
        -dsa | -disablesystemassertions
                      disable system assertions
        -agentlib:<libname>[=<options>]
                      load native agent library <libname>, e.g. -agentlib:hprof
                        see also, -agentlib:jdwp=help and -agentlib:hprof=help
        -agentpath:<pathname>[=<options>]
                      load native agent library by full pathname
        -javaagent:<jarpath>[=<options>]
                      load Java programming language agent, see java.lang.instrument
        -splash:<imagepath>
                      show splash screen with specified image
    navneeth@ubuntu:~$ javac -version
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
    Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
    	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:307)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: com.sun.tools.javac.Main.  Program will exit.

  2. #2
    Join Date
    Sep 2008
    Beans
    68

    Re: javac: could not find main class

    Have you tried simple programs? If you have, please provide the code
    Live Fast - Code Young. Soft engineering student's blog

    Ask me for anything but time. -Napoleon Bonaparte
    Ask me for anything but time to load Vista. -Me

  3. #3
    Join Date
    Oct 2007
    Beans
    1,914
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: javac: could not find main class

    A guess: You CLASSPATH environment variable is messed up. Please copy&paste its contents here.

  4. #4
    Join Date
    Aug 2006
    Beans
    458
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: javac: could not find main class

    Oh, yes, I have.

    Code:
    navneeth@ubuntu:~$ cat HelloWorld.java
    class HelloWorld
    {
        public static void main(String[] args) 
        { 
           System.out.println ("Hello, world!");
        }
    }  
    navneeth@ubuntu:~$ javac HelloWorld.java
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
    Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
    	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:307)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: com.sun.tools.javac.Main.  Program will exit.

  5. #5
    Join Date
    Aug 2006
    Beans
    458
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: javac: could not find main class

    Quote Originally Posted by Zugzwang View Post
    A guess: You CLASSPATH environment variable is messed up. Please copy&paste its contents here.
    Um, where can I find it?

    The last time I installed Java, which I think was in Gutsy, everything was smooth sailing. This is a fresh install of Jaunty and Java.

  6. #6
    Join Date
    Aug 2006
    Beans
    458
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: javac: could not find main class

    Oh, if you mean echo $CLASSPATH, then it's empty.

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Beans
    2,185
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: javac: could not find main class

    It looks like something is wrong with your JDK installation.

    How did you install Sun Java 6; from the repositories, or did you install it manually? Do you have other versions of Java installed?
    Ubuntu 12.04

  8. #8
    Join Date
    Aug 2006
    Beans
    458
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: javac: could not find main class

    From the repos. And no other version of java.

    apt-get install sun-java6-jdk --yes

    This error has been reported before, as a Google search will show, but I'm just not able to find a solution.
    Last edited by navneeth; May 19th, 2009 at 01:49 PM.

  9. #9
    Join Date
    Aug 2006
    Beans
    458
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: javac: could not find main class

    Bump.

  10. #10
    Join Date
    Jun 2006
    Location
    $ pwd _
    Beans
    3,999
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Re: javac: could not find main class

    In the folder where HelloWorld.java exists, run javac like below:
    Code:
     javac -cp .:$CLASSPATH HelloWorld.java
    If $CLASSPATH environment variable is set (perhaps in ~/.bashrc it will also be used for the compilation process. It will simply be ignored otherwise.

Page 1 of 2 12 LastLast

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
  •