作者KeeperOf7Key (七把钥匙的主人)
看板java
标题[问题] 用Eclipse输出jar的问题
时间Thu Jul 16 11:25:07 2009
我写了一个小小的寄email的程式然後发现在Eclipse里直接执行的时候一切正常。
但是只要汇出成jar的时候就发现执行会停在某一行addActionListener下。
而且我有加上try&catch在这一行的前後发现执行的时候停在这一行也没有出现
任何的exception,加上其他所有的addActionListener也都没有异常,所以完全
不知道是怎麽一回事@@" 麻烦各位大大帮忙~感恩!
相关程式码如下:
...
JButton sendB = new JButton("Send");
...
public void addons_2()
{
...
//停在这一行
sendB.addActionListener(new SendMail());
...
}
//Send E-mails (inner class)
private class SendMail implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
//A String for setting a SSL Encrypted transmission
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
//Various setting for an e-mail trasmission session
Properties pts = new Properties();
//Set the address of an SMTP server
pts.put("mail.smtp.host", smtpHost);
//SMTP server always requires authentication
pts.put("mail.smtp.auth", "true");
//Set the port of the SMTP server
pts.setProperty("mail.smtp.port", smtpPort);
//Set the encoding format of the data transmission as Unicode-8
pts.setProperty("mail.mime.charset", "UTF-8");
//If users decide to use SSL Encrypted transmission
if(SSL==true)
{
//Set SSL
pts.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
}
//Add all above properties into a session
Session s = Session.getDefaultInstance(pts, null);
try
{
//Set the transmission type of the session as SMTP
Transport trans = s.getTransport("smtp");
//Connect to the SMTP server with the address, username
//and password
trans.connect(smtpHost, username, password);
//Cyclically send each e-mail with different attachments
for(int loopa=0;loopa<toMail.length;loopa++)
{
//Create the e-mail
MimeMessage mail = new MimeMessage(s);
//Create the multipart of the email
Multipart mpt = new MimeMultipart();
//Create a body part of the multipart
MimeBodyPart mbody = new MimeBodyPart();
//Load the attachment
DataSource source =
new FileDataSource(attachTF[loopa].getText());
//Set the FROM address of the e-mail
mail.setFrom(new InternetAddress(fromMail));
//Set the title of the e-mail
mail.setSubject(titleS);
//Set the send-date of the e-mail
mail.setSentDate(new Date());
//Set the content to a mail body
mbody.setText(textS);
//Add the mail body of the content as one of
//the e-mail's multipart
mpt.addBodyPart(mbody);
//Create another body part
mbody = new MimeBodyPart();
//Set the attachment to this body part
mbody.setDataHandler(new DataHandler(source));
//Attach the filename to this body part (Optional?)
mbody.setFileName(attachTF[loopa].getText());
//Add the body part of the attachment as another one of the
mpt.addBodyPart(mbody);
//Set the TO address of the e-mail
mail.setRecipients(Message.RecipientType.TO, toMail[loopa]);
//Add the multipart into the e-mail
mail.setContent(mpt);
//Set the REAL(?) address for the transmission
InternetAddress[] address =
{
new InternetAddress(toMail[loopa])
};
//Send the e-mail
trans.sendMessage(mail, address);
}
//Close the connection with the SMTP server
trans.close();
//Close the window
processWindowEvent(new WindowEvent(new
JavaMail(),WindowEvent.WINDOW_CLOSING));
//Show a message of the successful transmission
JOptionPane.showMessageDialog(null, "E-mails are sent
normally.", "Transmission Complete",
JOptionPane.INFORMATION_MESSAGE);
}
//If unfortunately there's an Exception during the transmission
catch(Exception ex)
{
//Show why there's an exception
JOptionPane.showMessageDialog(null, ex +
"(If you don't understand this message, report to us)",
"Mailing failed", JOptionPane.ERROR_MESSAGE);
}
}
}
--
你来到了天母棒球场,这里正在进行一场棒球比赛。场上球员似乎火气很大呢!
(上火) 林岳平 (Lin Yue-Ping)
(闪光) 冯胜贤 (Feng Sheng-Xien)
[生命:86 精神:1079 体力:48]: throw Feng ball
你把一颗球丢到 冯胜贤 (Feng Sheng-xien)身上了!
你被传送到了法庭里!你一脸的茫然…
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.204.180.200
※ 编辑: KeeperOf7Key 来自: 123.204.180.200 (07/16 11:25)
1F:推 PsMonkey:SendMail 的细节咧.... @_@ 07/16 12:33
补落落长SendMail的细节…麻烦了<(_ _)>
2F:→ Schelfaniel:会不会是缺函式?? 07/16 13:40
另外补充就是用过winRAR开过包起来的jar有确定inner class的编译档也有包进去…
※ 编辑: KeeperOf7Key 来自: 123.204.180.214 (07/16 16:26)
※ 编辑: KeeperOf7Key 来自: 123.204.180.214 (07/16 16:30)
3F:推 PsMonkey:理论上应该没有缺 3rd class,有 exception 也会有反应.. 07/16 17:33
4F:推 PsMonkey:只一行行卡 out.print(),先抓死在那一行了 (好弱 Orz) 07/16 17:34
5F:→ PsMonkey:等等,那个 javax.net.ssl.SSLSocketFactory 真的有吗? 07/16 17:36
不过我抓是跑到addons_2里那一行addActionListener就停住了(後面还有validate();)
照理来说应该也还没用到SendMail里的任何一条码说(还没有按sendB呀…)…orz
另外"javax.net.ssl.SSLSocketFactory"我也不知道~还没测到这边XDrz
※ 编辑: KeeperOf7Key 来自: 123.204.180.214 (07/16 20:24)
6F:→ TonyQ:我视觉得你应该要先检查sendMail的建构子.. 07/17 16:57
7F:→ KeeperOf7Key:但是我SendMail没有写建构子呀… 07/19 00:35