1

I am learning how to use JavaMail. (i have se11)

I downloaded javax.mail.jar,
put it under C:\Java\jdk , and extract it.

I followed the instruction, set CLASSPATH = C:\Java\jdk\javax.mail.jar ;
and I add the javax.mail.jar to the eclispe Referenced Library.
However, when i try to import javax.mail.* , it says the import can not be resolved.

I open the extracted folder, and it contains only .class files.

I tried to open the javax.mail.Session file from eclipse file explorer, but it said:
"The JAR file C:\Java\jdk\bin\javax.mail.jar has no source attachment."

what should I do in order to import the javax.mail.* ?
I am very frustrated, please help!

BEI
  • 11
  • 1
  • 2
  • 1
    https://stackoverflow.com/questions/6606529/package-javax-mail-and-javax-mail-internet-do-not-exist – Abi May 28 '19 at 08:34
  • Possible duplicate of [package javax.mail and javax.mail.internet do not exist](https://stackoverflow.com/questions/6606529/package-javax-mail-and-javax-mail-internet-do-not-exist) – jpeg May 28 '19 at 08:35
  • Do you want to see the source in Eclipse or do you simply want to reference the javax.mail classes from within your program? – Chris Gerken May 29 '19 at 08:29
  • @ChrisGerken I just want to use the method in JavaMail, i dont need to see the source code. – BEI May 30 '19 at 03:21
  • @jpeg I already saw that question and followed what people suggested, but didn't work... – BEI May 30 '19 at 03:24

1 Answers1

1

No matter how you run your program, to just use the classes in a jar you need to have the jar file in your classpath. If you run from the command line you can do this:

java -cp C:\Java\jdk\javax.mail.jar  my.fully.qualified.classname

If you're in Eclipse then:

  1. Import the jar file into your Java project. Use the File-->Import... action.
  2. Select your java project and select Build Path --> Configure Build Path...
  3. Select Java Build Path on the left
  4. Select the Libraries tab and the Add Jars... button on the right
  5. Navigate to and select the jar you you imported above
  6. Click OK
  7. The classes in the jar file are now available for use in your code.
Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
  • I tried: File -> Import ->(select import wizard) Archive File ; and then I chose the Javamail.jar , after imported, the jar file is extracted into three folders under my project( com, javax, META-INF). So I am not able to do " Add Jars... ". What is going wrong? – BEI May 31 '19 at 02:55
  • @BEI - Import it as a regular file, not as an archive. You could also use the OS to copy the JAR into the actual folder and then in Eclipse refresh the project. – Chris Gerken Jun 01 '19 at 07:05