Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    solt is offline Member
    Join Date
    Dec 2009
    Posts
    12
    Rep Power
    0

    Question ===javac error===

    after install jdk

    set path=C:\Program Files\Java\jdk1.6.0_17\bin
    set classpath=C:\Program Files\Java\jdk1.6.0_17\lib\tools.jar;C:\Program Files\Java\jdk1.6.0_17\lib\dt.jar

    when i typed "javac" in command line ,shows the following error:

    C:\Documents and Settings\Administrator>javac
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main
    used by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Could not find the main class: com.sun.tools.javac.Main. Program will exit.

    i compile java file,it also show the error above
    but when i enter "java",it works

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default

    Get rid of that classpath; javac (as well as java and javaw) are native executable files and they know where to find the core classes.

    kind regards,

    Jos

  3. #3
    solt is offline Member
    Join Date
    Dec 2009
    Posts
    12
    Rep Power
    0

    Default

    i try it as you said ,but it doesn't work
    same error

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by solt View Post
    i try it as you said ,but it doesn't work
    same error
    Are you sure that 'classpath' environment variable is gone? Did you do a default install?

    kind regards,

    Jos

  5. #5
    solt is offline Member
    Join Date
    Dec 2009
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Are you sure that 'classpath' environment variable is gone? Did you do a default install?

    kind regards,

    Jos
    yes,i deleted 'classpath'
    and did a default install

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by solt View Post
    yes,i deleted 'classpath'
    and did a default install
    What happens when you type "echo %classpath%"? Is it really gone? To make sure, quit your shell/cmd and start a new one.

    kind regards,

    Jos

  7. #7
    solt is offline Member
    Join Date
    Dec 2009
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    What happens when you type "echo %classpath%"? Is it really gone? To make sure, quit your shell/cmd and start a new one.

    kind regards,

    Jos
    yes,i entered "echo %classpath%",it returns "%classpath%" only

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by solt View Post
    yes,i entered "echo %classpath%",it returns "%classpath%" only
    Hm, next to the bin directory you'll find a lib directory; does it contain a tools.jar file? If so open it with a zip program (but don't extract anything). Can you find the class com.sun.tools.javac.Main? If that directory (or that file) isn't there your installation might be corrupted by something ...

    kind regards,

    Jos

  9. #9
    solt is offline Member
    Join Date
    Dec 2009
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Hm, next to the bin directory you'll find a lib directory; does it contain a tools.jar file? If so open it with a zip program (but don't extract anything). Can you find the class com.sun.tools.javac.Main? If that directory (or that file) isn't there your installation might be corrupted by something ...

    kind regards,

    Jos
    yes,there is a 'Main.class' there

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by solt View Post
    yes,there is a 'Main.class' there
    I'm running out of ideas ... what happens when you type in "javac.exe"? (including the extension). Try that both in and outside that bin directory.

    kind regards,

    Jos

  11. #11
    solt is offline Member
    Join Date
    Dec 2009
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    I'm running out of ideas ... what happens when you type in "javac.exe"? (including the extension). Try that both in and outside that bin directory.

    kind regards,

    Jos
    in the bin directory the "javac.exe" execute success,outside it failures

  12. #12
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by solt View Post
    in the bin directory the "javac.exe" execute success,outside it failures
    Fails how? Does it show those exception stack traces or can't it find an executable file named "javac". If it's the latter check your path variable.

    Do you have other java versions installed?

    kind regards,

    Jos

  13. #13
    solt is offline Member
    Join Date
    Dec 2009
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Fails how? Does it show those exception stack traces or can't it find an executable file named "javac". If it's the latter check your path variable.

    Do you have other java versions installed?

    kind regards,

    Jos
    it shows the same error above ,and i just have one java version installed.

  14. #14
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by solt View Post
    it shows the same error above ,and i just have one java version installed.
    Let me get this straight: if you type just "javac" in your bin directory you get a listing on the screen that tells you how to use the compiler and its flags, right? But if you type that same outside of your bin directory you get that exception stack trace, right?

    If you use your 'search' facility in Microsoft Windows and search for "javac", what are the results?

    kind regards,

    Jos

  15. #15
    solt is offline Member
    Join Date
    Dec 2009
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Let me get this straight: if you type just "javac" in your bin directory you get a listing on the screen that tells you how to use the compiler and its flags, right? But if you type that same outside of your bin directory you get that exception stack trace, right?

    If you use your 'search' facility in Microsoft Windows and search for "javac", what are the results?

    kind regards,

    Jos
    just now,i find when i type javac after set path="C:\Program Files\Java\jdk1.6.0_17\bin" ,it works,but it failures after i close the cmd and type javac again

  16. #16
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by solt View Post
    just now,i find when i type javac after set path="C:\Program Files\Java\jdk1.6.0_17\bin" ,it works,but it failures after i close the cmd and type javac again
    Yes, that's what happens: if you define environment variables in your cmd they're only valid during that session (as long as that particular cmd runs) and they're gone when your cmd is gone. Use your control panel to set those environment variables permanently.

    But what happened to that mysterious exception stack trace?

    kind regards,

    Jos

  17. #17
    solt is offline Member
    Join Date
    Dec 2009
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Yes, that's what happens: if you define environment variables in your cmd they're only valid during that session (as long as that particular cmd runs) and they're gone when your cmd is gone. Use your control panel to set those environment variables permanently.

    But what happened to that mysterious exception stack trace?

    kind regards,

    Jos
    i use control panel set those environment variables from the beginning

  18. #18
    solt is offline Member
    Join Date
    Dec 2009
    Posts
    12
    Rep Power
    0

    Default

    i reinstall the xp system ,and erverthing is ok
    thanks for you help

  19. #19
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,354
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by solt View Post
    i reinstall the xp system ,and erverthing is ok
    thanks for you help
    What OS did you have installed before? I have installed Java on XP, Vista and 7 without problems ...

    kind regards,

    Jos

  20. #20
    solt is offline Member
    Join Date
    Dec 2009
    Posts
    12
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    What OS did you have installed before? I have installed Java on XP, Vista and 7 without problems ...

    kind regards,

    Jos
    i installed it also on xp before.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 3
    Last Post: 08-14-2009, 12:57 PM
  2. javac?
    By sardare in forum Eclipse
    Replies: 1
    Last Post: 06-14-2008, 02:06 AM
  3. javac DOS
    By rdunne in forum New To Java
    Replies: 3
    Last Post: 01-01-2008, 11:49 AM
  4. Replies: 2
    Last Post: 07-30-2007, 08:55 AM
  5. Help with javaC
    By Daniel in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 02:44 PM

Tags for this Thread

Posting Permissions

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