(newbie) importing JavaMail jar

Discussion in 'Mac Programming' started by daniz, Apr 25, 2009.

  1. daniz macrumors newbie

    Joined:
    Apr 25, 2009
    #1
    Hi.

    I am new to Mac (to this forum too) and I am having some problem while developing in java.

    I have to use the javax.mail classes in my class. I downloaded the JavaMail API and tried to install, apparently with no success.
    When I import the jar in my project (import javax.mail), java can't resolve the name.

    I think the problem is how I am installing the JavaMail API. I followed the readme and set the classpath in this way:

    export CLASSPATH=$CLASSPATH:/System/Library/Java/javamail-1.4.2/mail.jar

    export CLASSPATH=$CLASSPATH:/System/Library/Java/jaf-1.1.1/activation.jar


    Still I can't import this jar in my project.

    I know I'm doing something wrong but I can't tell what. Any help will be appreciated. Thanks.

    Daniz
     
  2. pikester macrumors newbie

    pikester

    Joined:
    Feb 27, 2009
    #2
    Daniz:
    You can see my terminal session below. When I first try to compile HelloWorld, it won't compile since the mail.jar file is not in the classpath. When I add it via the command line, I can compile the class:
    Code:
    howe:play kevin$ ls
    HelloWorld.java		activation-1.1.jar	mail.jar
    howe:play kevin$ cat HelloWorld.java 
    import javax.mail.internet.InternetAddress;
    
    public class HelloWorld
    {
      public static void main(String[] args)
      {
        System.out.println("Hello World!");
      }
    }
    
    howe:play kevin$ javac HelloWorld.java 
    HelloWorld.java:1: package javax.mail.internet does not exist
    import javax.mail.internet.InternetAddress;
                               ^
    1 error
    howe:play kevin$ export CLASSPATH=$PWD/activation-1.1.jar:$PWD/mail.jar
    howe:play kevin$ javac HelloWorld.java 
    howe:play kevin$ 
    Things to note:
    • When you "import", are you just importing javax.mail or are you trying to import a specific class?
    • What are you using to compile your code? You are using the phrase "I can't import this jar in my project". Are you doing this from the command line or from an IDE? If you are using javac from the command line, it looks like everything should be fine. If you are using an IDE, you'll need to import the jar into the IDE.
     
  3. daniz thread starter macrumors newbie

    Joined:
    Apr 25, 2009
    #3
    Hi. The problem was the improper use of build path of eclipse.

    Many thanks your post helped me to find it out.

    Cheers.

    Daniz
     

Share This Page