problem setting classpath of javamail?

徘徊边缘 提交于 2019-12-13 06:45:59

问题


I downloaded java mail because i wanted to run the code that had header files :

import javax.mail.*;

import javax.mail.internet.*

But even after setting the class path i am unable to run that code.

The jar files included in java mail are :

  1. mail.jar
  2. dsn.jar
  3. imap.jar
  4. mailapi.jar
  5. pop3.jar
  6. smtp.jar

I edited my classpath variable and finally it was :

C:\Program Files\Java\jdk1.7.0\lib;C:\Program Files\Java\javamail-1.4.4\mail.jar;C:\Program Files\Java\javamail-1.4.4\lib;.;

The first jar file is in a seperate directory and the remaining jar files are in one directory.

If the class path is set wrong , then please tell the mistake. (i have taken the correct directories)

If there is no problem with the class path then what is the problem ?


回答1:


You need to specify each single jar separately in classpath, specifying directory with jars won't work.




回答2:


Wildcards can be used as part of the classpath. Pls refer here for more information.




回答3:


You make the Java runtime aware of your JAR with the -cp option:

java -cp E:\yourjarfile.jar com.yourpackage.YourProgram

You can do the same via the CLASSPATH environment variable:

set CLASSPATH="E:\yourjarfile.jar;E:\yourotherjarfile.jar"

See this Windows example.

Also, this was answered before.




回答4:


Let's say I have a directory "C:\Users\excont\Desktop\Send Mail" which contains all jar files & Java class.

so just follow this step. You will definitely get the result

C:\Users\excont\Desktop\Send Mail>set CLASSPATH=dsn.jar;imap.jar;mailapi.jar;pop3.jar;smtp.jar;.;

C:\Users\excont\Desktop\Send Mail>javac SendMail.java

C:\Users\excont\Desktop\Send Mail>java SendMail

Hope I could help you or anyone searching for the same.



来源:https://stackoverflow.com/questions/6607388/problem-setting-classpath-of-javamail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!