Search code examples
eclipsedeploymentbuildglassfishjakarta-mail

JavaMail crashes after build/deploy on Glassfish 4


My current project includes using of a JavaMail for confirming an user email. The problem I have is that, using eclipse, every time I build & deploy my web application on the local Glassfish server the JavaMail crashes with the following exception:

Severe: java.lang.SecurityException: Access to default session denied
at javax.mail.Session.getDefaultInstance(Session.java:333)
at utils.MailService.sendEmailSSL(MailService.java:58)

And here the code snipped where I'm obtaining the session and which is throwing the above exception:

Session session = Session.getDefaultInstance(
                     props,
                     new javax.mail.Authenticator(){
                        protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(usr, pwd);
                    }
                });

The workaround I've found so far is restarting Glassfish and after that JavaMail functions properly again. The problem is it is very annoying and time consuming doing a restart even after the smallest change in my code.

My question: Is there a possibility to reset only the JavaMail service and bind this with the build event?

Off course any other suggestions are welcome too :)


Solution

  • If you can avoid using Session.getDefaultInstance. Use Session.getInstance and fix some of the common mistakes.