sdc248
asked on
java.lang.SecurityException
Hi:
I copied a project from one folder to another in the file System. Then I opened it through eclipse and tried to run the programs. I got the following error message when the program starts by creating an object:
java.lang.SecurityExceptio n: class "javax.mail.Message"'s signer information does not match signer information of other classes in the same package.
I have a mail.jar on the project's buildpath and at the end of the program an email will be sent. But the exception is thrown at a line that is still far from sending emails.
Please help.
I copied a project from one folder to another in the file System. Then I opened it through eclipse and tried to run the programs. I got the following error message when the program starts by creating an object:
java.lang.SecurityExceptio
I have a mail.jar on the project's buildpath and at the end of the program an email will be sent. But the exception is thrown at a line that is still far from sending emails.
Please help.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I did some testing and found the problem is with a class called Data. Data has two email sending functions together with a bunch of public static variables, which are referenced each time an object is created. If I commented out these two email functions, the problem would be gone, but of course the problem would have problem sending emails. Any thoughts?
public static void sendEmail(String title, String content, String[] mailingList) {
try {
Address[] addresses_to = new InternetAddress[mailingLis t.length];
for (int i=0; i<mailingList.length; i++) {
addresses_to[i]= new InternetAddress(mailingLis t[i]);
}
Properties props = new Properties();
props.put("mail.host", "mailserver");
Session mailConnection = Session.getInstance(props, null);
Message msg = new MimeMessage(mailConnection );
Address sender = new InternetAddress ("notifications@camenergy. com", "system");
msg.setContent(content, "text/plain");
msg.setFrom(sender);
msg.setRecipients(Message. RecipientT ype.TO, addresses_to);
msg.setSubject(title);
Transport.send(msg);
System.out.println("email sent.");
} catch (Exception e) {
e.printStackTrace();
System.out.println("fail to send email.");
}
}
public static void sendEmail(String title, String content,
File attachment, String[] mailingList) {
try {
Address[] addresses_to = new InternetAddress[mailingLis t.length];
for (int i=0; i<mailingList.length; i++) {
addresses_to[i]= new InternetAddress(mailingLis t[i]);
}
Properties props = new Properties();
props.put("mail.host", "mailserver");
Session mailConnection = Session.getInstance(props, null);
Message msg = new MimeMessage(mailConnection );
//Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
//Fill the message
messageBodyPart.setText(co ntent);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mess ageBodyPar t);
//Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(attachment) ;
messageBodyPart.setDataHan dler(new DataHandler(source));
messageBodyPart.setFileNam e(attachme nt.getName ());
multipart.addBodyPart(mess ageBodyPar t);
// Put parts in message
msg.setContent(multipart);
Address sender = new InternetAddress ("notifications@camenergy. com", "system");
msg.setFrom(sender);
msg.setRecipients(Message. RecipientT ype.TO, addresses_to);
msg.setSubject(title);
Transport.send(msg);
System.out.println("email sent.");
} catch (Exception e) {
e.printStackTrace();
System.out.println("fail to send email.");
}
}
public static void sendEmail(String title, String content, String[] mailingList) {
try {
Address[] addresses_to = new InternetAddress[mailingLis
for (int i=0; i<mailingList.length; i++) {
addresses_to[i]= new InternetAddress(mailingLis
}
Properties props = new Properties();
props.put("mail.host", "mailserver");
Session mailConnection = Session.getInstance(props,
Message msg = new MimeMessage(mailConnection
Address sender = new InternetAddress ("notifications@camenergy.
msg.setContent(content, "text/plain");
msg.setFrom(sender);
msg.setRecipients(Message.
msg.setSubject(title);
Transport.send(msg);
System.out.println("email sent.");
} catch (Exception e) {
e.printStackTrace();
System.out.println("fail to send email.");
}
}
public static void sendEmail(String title, String content,
File attachment, String[] mailingList) {
try {
Address[] addresses_to = new InternetAddress[mailingLis
for (int i=0; i<mailingList.length; i++) {
addresses_to[i]= new InternetAddress(mailingLis
}
Properties props = new Properties();
props.put("mail.host", "mailserver");
Session mailConnection = Session.getInstance(props,
Message msg = new MimeMessage(mailConnection
//Create the message part
BodyPart messageBodyPart = new MimeBodyPart();
//Fill the message
messageBodyPart.setText(co
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mess
//Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(attachment)
messageBodyPart.setDataHan
messageBodyPart.setFileNam
multipart.addBodyPart(mess
// Put parts in message
msg.setContent(multipart);
Address sender = new InternetAddress ("notifications@camenergy.
msg.setFrom(sender);
msg.setRecipients(Message.
msg.setSubject(title);
Transport.send(msg);
System.out.println("email sent.");
} catch (Exception e) {
e.printStackTrace();
System.out.println("fail to send email.");
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am not sure I understand you.
By "in the javax.mail package" you mean classes that import javax.mail packages?
"Rename the package".. the package that contains above mentioned classes?
By "in the javax.mail package" you mean classes that import javax.mail packages?
"Rename the package".. the package that contains above mentioned classes?
No I mean your application classes, make sure that you are not using that package name.
Also check that u don't have two copies of mail.jar available in classpath.
Also check that u don't have two copies of mail.jar available in classpath.
ASKER
I resolved the problem by moving the two email related functions away from Data class so they are no longer involved in the object creation process. It worked although I still don't know what happened. Anyway, thank you guys for trying to help.
:-)
> Sign all classes and jars with the same cert if they need to be signed
that had nothing to do with your problem :)
that had nothing to do with your problem :)
ASKER