首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

java.lang.NoClassDefFoundError异常解决方法!

2014-01-26 
java.lang.NoClassDefFoundError 异常:用eclipse建立一个java工程,路径:D:\matrix\workspace\email,在该路

java.lang.NoClassDefFoundError 异常:

用eclipse建立一个java工程,路径:D:\matrix\workspace\email,在该路径下:D:\matrix\workspace\email\com\matrix\send,有个发送电子邮件的类SimpleSender,其.java文件如下:
-------------------------------------------------------------
package com.matrix.send;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class SimpleSender {

/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
try{

String smtpServer=args[0];

String to=args[1];

String from=args[2];

String subject=args[3];

String body=args[4];

send(smtpServer, to, from, subject, body);
}
catch (Exception ex)
{
System.out.println( "Usage: java com.matrix.send.SimpleSender "
+ " smtpServer toAddress fromAddress subjectText bodyText ");
}

System.exit(0);
}

public static void send(String smtpServer, String to, String from, String subject, String body)
{

try
{

Properties props = System.getProperties();
// -- Attaching to default Session, or we could start a new one --
props.put( "mail.smtp.host ", smtpServer);
Session session = Session.getDefaultInstance(props, null);
// -- Create a new message --
Message msg = new MimeMessage(session);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to, false));

// -- We could include CC recipients too --
// if (cc != null)
// msg.setRecipients(Message.RecipientType.CC
// ,InternetAddress.parse(cc, false));
// -- Set the subject and body text --

msg.setSubject(subject);
msg.setText(body);

// -- Set some other header information --
msg.setHeader( "X-Mailer ", "LOTONtechEmail ");
msg.setSentDate(new Date());

// -- Send the message --
Transport.send(msg);
System.out.println( "Message sent OK. ");
}
catch (Exception ex)
{
System.out.println( "send error! ");
ex.printStackTrace();
}
}
}
--------------------------------------------------------------
在命令行:
D:\matrix\workspace\email\com\matrix\send> java SimpleSender smtp.tom.com matrix2005 matrix2005 "test " "test "

Exception in thread "main " java.lang.NoClassDefFoundError: SimpleSender

请问怎么解决?

------解决方法--------------------------------------------------------
错了。

应该是在D:\matrix\workspace\email下输入:
java com.matrix.send.SimpleSender smtp.tom.com matrix2005 matrix2005 "test " "test "
------解决方法--------------------------------------------------------
在命令行下输入JAVA+类名的时候要把包的名字也包括下去P.S:为什么不在ECLIPSE内直接运行还跑到命令行下。

        

热点排行