Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default [SOLVED] Could not find the main class: error...

    OK, one more thing... I hope.

    Sometimes I just feel helpless...

    I compiled my little program with netbeans. I than ran it with netbeans and everything is perfect. However, when I want to run it from the command prompt, it spazes out on me! So, I tried compiling it from the command line, but I get the same error when I attempt to run it...

    This is what I get:
    Java Code:
    bob@GeorgeJr:~/Programming/java/NetBeans/SendMail/build/classes$ java SendMail
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
    Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
            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: SendMail.  Program will exit.
    bob@GeorgeJr:~/Programming/java/NetBeans/SendMail/build/classes$
    This error makes no sense to me. I don't know where even to begin on decoding this error...

    Once again, I thank you for your help!
    Last edited by bobleny; 04-02-2009 at 11:04 PM.
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    That's because javax.mail package is not in the same place as your main class is contain. Or not in the class path. I hope you import those packages from the NetBeans.

  3. #3
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    javax.mail API is not part of core java API
    -cp the mail.jar in netbeans
    Last edited by mtyoung; 04-02-2009 at 10:34 AM.

  4. #4
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default

    I have mail.jar listed as a compile time library, which allows it to compile. I don't understand why it wont run then?
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    You are talking in related with NetBeans right?

    NetBeans refer the path when you import the package from the project properties. But command prompt doesn't know that.

  6. #6
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default

    Yeah, I understand that netbeans knows where they are, which is why it will run in netbeans.

    Theres got to be a way to "package" the class and jar files so that it runs on command line right?
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

  7. #7
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default

    This is the command I used to compile the program via the command line:
    Java Code:
    javac -classpath "/home/bob/.java/MyJars/*" SendMail.java
    It compiles fine, I set the classpath, I just don't understand why it wont run... :'(
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  9. #9
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default

    Well, could someone explain this classpath thing to me? I obviously just don't understand...

    I thought, [-classpath "/home/bob/.java/MyJars/*"] was setting the classpath.

    I've read a bunch of different articles that explain what it is, but nothing I've read seems to be able to tell me how to do it in a comprehensive way.

    This is so frustrating...
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

  10. #10
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    when you use the -cp or -classpath switch, its not permanent. so "Try to add those packages in to the classpath and try to run the application."
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  11. #11
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default

    Thank god!

    I typed this in (Note: this command will only work on linux!):
    Java Code:
    export CLASSPATH=$CLASSPATH:/home/bob/.java/MyJars/mail.jar:.
    Now it works! :D

    Thank you all for your help!
    Last edited by bobleny; 04-03-2009 at 07:12 AM.
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  13. #13
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default

    In the teminal.
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

  14. #14
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  15. #15
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default

    Well, kind of. As it turns out, after I reboot my computer I have to type the command in again. However, I only need to type it once per boot.

    In my readings, I remember the mentioning of ".bashrc" file in my home directory. I think that if I copy that command into that file, It will always work... We will see what happens.

    Edit-
    Placing the command in .bashrc, does the trick! After rebooting, the classpath is still there!
    Last edited by bobleny; 04-03-2009 at 10:41 PM.
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

  16. #16
    vijayabaskar is offline Member
    Join Date
    Apr 2009
    Posts
    37
    Rep Power
    0

    Default

    give correct path name

  17. #17
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by bobleny View Post
    Well, kind of. As it turns out, after I reboot my computer I have to type the command in again. However, I only need to type it once per boot.

    In my readings, I remember the mentioning of ".bashrc" file in my home directory. I think that if I copy that command into that file, It will always work... We will see what happens.

    Yes, you are working on Linux. So you need to do this only once in boot-up. I'm not an expert on Linux, but seems to me that .bashrc file quite similar to autoexec.bat file in windows.

  18. #18
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by vijayabaskar View Post
    give correct path name
    Can you explain bit more what the correct path name means?

  19. #19
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default

    Just a quick update...
    Placing the classpath command in .bashrc, does allow it to work immediately after a reboot.

    I have also finished my program and it does exactly what it is supposed to do!

    Thanks again for all your help!
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

  20. #20
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 09-22-2011, 10:48 PM
  2. Replies: 6
    Last Post: 05-18-2010, 06:11 PM
  3. Could not find the main class, program will exit.
    By aryubi in forum New To Java
    Replies: 39
    Last Post: 02-19-2010, 11:02 AM
  4. Could not find main class - JDK 1.6
    By Syranno in forum New To Java
    Replies: 1
    Last Post: 07-25-2008, 05:07 PM
  5. JVM Could not find main class
    By banduskank in forum Advanced Java
    Replies: 2
    Last Post: 06-24-2008, 09:05 AM

Posting Permissions

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