Exception in thread "main" java.lang.NoClassDefFoundError: SendMailTLSDFC

Discussion in 'Java' started by deepak, Apr 10, 2012.

  1. deepak

    deepak Guest

    Hi, I have created a java file for sending a file to my mail. I am
    using mail.jar file. I am able to create .class file properly. But am
    unable to run this file using java command on command prompt.
    javac -cp D:\mail.jar SendMailTLSDFC.java
    above command is working properly.
    It creates 2 class as mentioned below
    SendMailTLSDFC$1.class
    SendMailTLSDFC.class

    but when i am trying to run following command I am getting an error.
    java -cp D:\mail.jar SendMailTLSDFC
    Exception in thread "main" java.lang.NoClassDefFoundError:
    SendMailTLSDFC

    Kindly help
    deepak, Apr 10, 2012
    #1
    1. Advertising

  2. deepak

    GGolf Guest

    On 04/10/2012 02:10 PM, deepak wrote:
    > Hi, I have created a java file for sending a file to my mail. I am
    > using mail.jar file. I am able to create .class file properly. But am
    > unable to run this file using java command on command prompt.
    > javac -cp D:\mail.jar SendMailTLSDFC.java
    > above command is working properly.
    > It creates 2 class as mentioned below
    > SendMailTLSDFC$1.class
    > SendMailTLSDFC.class
    >
    > but when i am trying to run following command I am getting an error.
    > java -cp D:\mail.jar SendMailTLSDFC
    > Exception in thread "main" java.lang.NoClassDefFoundError:
    > SendMailTLSDFC


    Did you try adding the current folder (.) to the classpath?
    GGolf, Apr 10, 2012
    #2
    1. Advertising

  3. deepak

    Lew Guest

    GGolf wrote:
    > deepak wrote:
    > > Hi, I have created a java [sic] file for sending a file to my mail. I am
    > > using mail.jar file. I am able to create .class file properly. But am
    > > unable to run this file using java command on command prompt.
    > > javac -cp D:\mail.jar SendMailTLSDFC.java
    > > above command is working properly.
    > > It creates 2 class as mentioned below
    > > SendMailTLSDFC$1.class
    > > SendMailTLSDFC.class
    > >
    > > but when i am trying to run following command I am getting an error.
    > > java -cp D:\mail.jar SendMailTLSDFC
    > > Exception in thread "main" java.lang.NoClassDefFoundError:
    > > SendMailTLSDFC

    >
    > Did you try adding the current folder (.) to the classpath?


    In addition to GGolf's fine advice, which should solve that immediate problem, let me add a couple of extras:

    - http://sscce.org/
    This fine discussion of the Simple, Self-Contained Compilable (Correct) Example (SSCCE) by Andrew Thompson will help you two ways. Creating an exampleoften reveals the problem to you before you post your question, and the example isolates your issue and makes it easier for people to respond sensibly. GGolf was clever to figure out your issue without an SSCCE.

    - Use packages.
    You put 'SendMailTLSDFC' in the default package, or "no-package" package. Don't do that.

    Also, study the Java tutorial and other documentation on classpaths.

    --
    Lew
    Lew, Apr 10, 2012
    #3
  4. deepak

    deepak Guest

    On Tuesday, April 10, 2012 2:10:43 PM UTC+5:30, deepak wrote:
    > Hi, I have created a java file for sending a file to my mail. I am
    > using mail.jar file. I am able to create .class file properly. But am
    > unable to run this file using java command on command prompt.
    > javac -cp D:\mail.jar SendMailTLSDFC.java
    > above command is working properly.
    > It creates 2 class as mentioned below
    > SendMailTLSDFC$1.class
    > SendMailTLSDFC.class
    >
    > but when i am trying to run following command I am getting an error.
    > java -cp D:\mail.jar SendMailTLSDFC
    > Exception in thread "main" java.lang.NoClassDefFoundError:
    > SendMailTLSDFC
    >
    > Kindly help



    Hi,
    Thanks so much for your reply GGolf and Lew.
    GGolf, I tried . also and I got the result as shown below.
    D:\project>java . SendMailTLSDFC
    Exception in thread "main" java.lang.NoClassDefFoundError: /

    Lew,
    I had used packages but i just removed it from the current file before posting the question here just reduce the complexities.

    Kindly help
    deepak, Apr 11, 2012
    #4
  5. deepak

    Paul Cager Guest

    On Apr 11, 12:19 pm, deepak <> wrote:
    > I tried . also and I got the result as shown below.
    > D:\project>java . SendMailTLSDFC
    > Exception in thread "main" java.lang.NoClassDefFoundError: /


    You need

    java -cp . SendMailTLSDFC

    Otherwise the java command assumes "." is the name of the class you
    are trying to run.
    Paul Cager, Apr 11, 2012
    #5
  6. deepak

    Lew Guest

    Paul Cager wrote:
    > deepak wrote:
    >> I tried . also and I got the result as shown below.
    >> D:\project>java . SendMailTLSDFC
    >> Exception in thread "main" java.lang.NoClassDefFoundError: /

    >
    > You need
    >
    > java -cp . SendMailTLSDFC
    >
    > Otherwise the java command assumes "." is the name of the class you
    > are trying to run.


    Deepak, you should read the documentation on the "javac" and "java" commands.

    Randomly tossing strings into your command isn't nearly as effective as
    looking up the correct syntax and using it.

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, Apr 11, 2012
    #6
  7. deepak

    GGolf Guest

    On 04/11/2012 06:14 PM, Paul Cager wrote:
    > On Apr 11, 12:19 pm, deepak<> wrote:
    >> I tried . also and I got the result as shown below.
    >> D:\project>java . SendMailTLSDFC
    >> Exception in thread "main" java.lang.NoClassDefFoundError: /

    >
    > You need
    >
    > java -cp . SendMailTLSDFC
    >
    > Otherwise the java command assumes "." is the name of the class you
    > are trying to run.


    To the OP: You'll need mail.jar on the classpath too, so the command
    will be:

    java -cp D:\mail.jar;. SendMailTLSDFC
    GGolf, Apr 12, 2012
    #7
  8. deepak

    Lew Guest

    GGolf wrote:
    > Paul Cager wrote:
    >> deepak wrote:
    >>> I tried . also and I got the result as shown below.
    >>> D:\project>java . SendMailTLSDFC
    >>> Exception in thread "main" java.lang.NoClassDefFoundError: /

    >>
    >> You need
    >>
    >> java -cp . SendMailTLSDFC
    >>
    >> Otherwise the java command assumes "." is the name of the class you
    >> are trying to run.

    >
    > To the OP: You'll need mail.jar on the classpath too, so the command
    > will be:
    >
    > java -cp D:\mail.jar;. SendMailTLSDFC


    <http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html>

    --
    Lew
    Lew, Apr 12, 2012
    #8
  9. deepak

    deepak Guest

    Thanks a lot evrybody,
    java -cp D:\mail.jar;. SendMailTLSDFC
    Above command worked.

    Deepak
    :)


    On Tuesday, April 10, 2012 2:10:43 PM UTC+5:30, deepak wrote:
    > Hi, I have created a java file for sending a file to my mail. I am
    > using mail.jar file. I am able to create .class file properly. But am
    > unable to run this file using java command on command prompt.
    > javac -cp D:\mail.jar SendMailTLSDFC.java
    > above command is working properly.
    > It creates 2 class as mentioned below
    > SendMailTLSDFC$1.class
    > SendMailTLSDFC.class
    >
    > but when i am trying to run following command I am getting an error.
    > java -cp D:\mail.jar SendMailTLSDFC
    > Exception in thread "main" java.lang.NoClassDefFoundError:
    > SendMailTLSDFC
    >
    > Kindly help
    deepak, Apr 13, 2012
    #9
  10. deepak

    Lew Guest

    deepak wrote:
    > Thanks a lot evrybody,
    > java -cp D:\mail.jar;. SendMailTLSDFC
    > Above command worked.


    Thank you very much for showing us what worked.

    (P.S. - Please do not top-post.)

    --
    Lew
    Lew, Apr 13, 2012
    #10
  11. deepak

    Roedy Green Guest

    On Tue, 10 Apr 2012 18:56:50 +0530, GGolf <> wrote,
    quoted or indirectly quoted someone who said :

    >NoClassDefFoundError


    see
    http://mindprod.com/jgloss/runerrormessages.html#NOCLASSDEFFOUNDERROR
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    Programmers love to create simplified replacements for HTML.
    They forget that the simplest language is the one you
    already know. They also forget that their simple little
    markup language will bit by bit become even more convoluted
    and complicated than HTML because of the unplanned way it grows.
    ..
    Roedy Green, Apr 29, 2012
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page