请问 javamail 发送程序编译问题

08-02-17 hyb

同样的程序在jdk1.4 下可以编译运行 但jdk1.5下不能编译
public class Send
{
public static void main(String args[]) throws Exception
{

String host = "smtp.sohu.com";
String from = "aaa@sohu.com";
String to = "aaa@hotmail.com";
String username = "aaa";
String password = "1223456";

// Get system properties
// Properties props = System.getProperties();
Properties props = new Properties();

// Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");

// Get session
Session session = Session.getDefaultInstance(props);

// watch the mail commands go by to the mail server
session.setDebug(true);

// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");

// Send message
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}



}


抛出异常如下:
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Exception in thread "main"

banq
2008-02-19 11:01
>UnsupportedClassVersionError
可能是编译环境的问题,换JDK要将以前的JDK和class都清除。

猜你喜欢