2

I am using Java SE with Eclipse happily but now I am going to write a "send mail" program which requires javax.mail package. I found that in Java EE so I downloaded one (180MB) and I know that Java EE installation needs SE JDK/JRE. Because I installed Java SE in c:\java\jdk1.7 (not the default path) I use -j c:\java\jdk1.7 to install Java EE. I have several questions about it.

  1. How could I let Eclipse to load the Java EE package? Should I change the JRE in Java EE? Now Eclipse still only know the SE lib.

  2. Do we have a JDK version which include APIs from Java EE? Because I really do not want to install two JREs in my computer and I do not need Glassfish. Can some one tell me which one I should download?

  3. Is there src.zip for Java EE api? I cannot find it.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user1722361
  • 377
  • 1
  • 4
  • 14
  • 5
    You don't need Java EE to use the Java Mail API, I quote *The JavaMail API is available as an optional package for use with Java SE platform* available from [here](http://www.oracle.com/technetwork/java/javamail/index-138643.html) – MadProgrammer Oct 07 '12 at 22:02
  • In any case, if you only need to write a send mail program, you don't need the whole Java EE monster. You can use Java SE and include both mail.jar and activation.jar into your classpath. – Guido Oct 07 '12 at 22:02
  • You're right that you don't need Glassfish for JavaMail, but that 180MB which you downloaded is basically Glassfish :) Related: http://stackoverflow.com/questions/7295096/what-exactly-is-java-ee/7295697#7295697 and http://stackoverflow.com/questions/12163374/netbeans-how-to-add-java-ee-container-to-java-project/12163715#12163715 – BalusC Oct 07 '12 at 22:06
  • 1
    You should probably use `maven` to avoid this category of headache. (And gain several new many more interesting categories of headache.) – millimoose Oct 07 '12 at 22:20

1 Answers1

3

Getting Java mail

Download Java Mail API from Oracle website. Exctract the JARs (mailapi.jar has the desired java.mail package) and put in yout CLASSPATH by:

RightClick(project) -> properties -> Java Build Path -> Libraries 
-> add Jars/Add External Jars (depends where you put your JARS)

Updating the JRE In your eclipse, use the menu options as below:

    window -> preferences->  Java -> Installed JREs -> Add

Give the path as c:\java\jdk1.7 and follow the steps to complete. Once done, JDK 1.7 will appear in the list with checkbox in front. Select the checkbox and press OK.

You should be all set, if you haven't done any project specific settings.

To verify the project specific settings, follow the steps:

    RightClick(project) -> properties -> Java Build Path -> Libraries.

Your JDK 1.7 should appear in right pane.

Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
  • Hi Thanks I know how to set jre in Installed JREs. The problem is that c:\java\jdk1.7 is my java se path, the java ee is in c:\glassfish. Should I set the JRE in the glassfish to use java ee? – user1722361 Oct 07 '12 at 22:00
  • 1
    Please note that whilst this answers OP's concrete question, this way the OP is actually still going in the wrong direction as to achieving the concrete functional requirement of using JavaMail in a Java SE application. – BalusC Oct 07 '12 at 22:09
  • Updated the answer with additional steps of getting JAVA Mail API. – Yogendra Singh Oct 07 '12 at 22:18
  • @BalusC, what do you recommend he do then? – oconnor0 Oct 07 '12 at 22:22
  • @oconnor0: just start reading the [JavaMail FAQ / developer guide](http://www.oracle.com/technetwork/java/faq-135477.html). – BalusC Oct 07 '12 at 22:23