你們讓我很自覺......我會盡力讓這個更好。Java程序在Windows 7上工作,但不是Windows 8?
好的,所以這個程序(不要殺我..我下載它)只能在Windows 7和Ubuntu上工作,據我所知。當你在Windows 8上打開它時,它會顯示「Java異常錯誤」。
我在想這個和文件末尾的catch(messagingException ex)
有關。我承認,我對java一無所知,但你必須從某處開始......不是嗎?我知道java適用於所有平臺!
我也嘗試過這個程序有多個文件和多個Gmail帳戶......我甚至用我的康卡斯特電子郵件地址試了一下。
我使用「JavaMailAPI」(http://www.oracle.com/technetwork/java/javamail/index.html)作爲實際的郵件部分。
當我打開它在Windows 8終端它給了我這樣的:
Exception in thread "Main" java.lang.noclassdeffounderror: java/mail/mailexception
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.langf.Class.privateGetDdecLaredMethods(Unkown source)
at java.lang.Class.getMethod(unknown source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown source)
caused by: java.lang.classnotfoundexception: java.mail.messagingException
at java.net.URLCLassLoader$1.run(unknown source)
at java.net.URLClassLoader$1.run(Unknown source)
at java.security.AccessController.doPrivaleged(native Method)
at java.net.URLClassLoader.findClass(Unknown source)
at java.lang.ClassLoader.findClass(Unkown source)
at jaa.lang.CLassLoader.loadClass(Unknown source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown source)
at java.lang.ClassLoader.loadClass(Unknown source)
... 6 more
下面是代碼:
package testing;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Testing{
public static void main(String[] args) {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("Email","Password");
}
});
try {
BodyPart messageBodyPart = new MimeBodyPart();
Multipart multipart = new MimeMultipart();
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("Email Address"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("Email Address to send "));
message.setSubject("Subject");
message.setText("Message");
String filename = "attachment location";
DataSource source = new FileDataSource(filename);
message.setDataHandler(new DataHandler(source));
message.setFileName(filename);
multipart.addBodyPart(messageBodyPart);
Transport.send(message);
System.out.println("Done");
} catch (MessagingException ex) {
Logger.getLogger(Testing.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
如果您需要任何其他有關程序請查詢!
顯然Windows 8上的計算機上缺少'java.mail'包(JAR文件) – 2013-02-17 15:16:44
您在這些系統上運行的是哪個版本的Java?哪些庫與應用程序一起打包? – toniedzwiedz 2013-02-17 15:17:25
我在兩臺機器上運行Java 7u13,並且JavaMail應該與它打包在一起..但它似乎不是。我假設這將是我的問題,我如何打包一個圖書館的程序? – Leetfail 2013-02-17 15:19:10