Problems using JavaMail within hosted mode in Eclipse

311 views
Skip to first unread message

Ryan McFall

unread,
Jun 21, 2012, 6:39:39 AM6/21/12
to google-we...@googlegroups.com
In trying to configure an SMTPAppender for use with log4j so that error reports on the server can be emailed out, I ran into difficulties getting JavaMail to work correctly.  I found many posts indicating that the problem is either:
  1. multiple copies of the JavaMail classes in the classpath
  2. issues with classloaders, related to the servlet container
To isolate the problem, I created a sample webapp using the GWT Eclipse plugin, and modified the auto-generated server-side greet method to log an error message, with an appropriately configured log4j.properties file.  The only two jar files in the WEB-INF/lib folder are the log4j-1.2.17.jar, mail.jar and gwt-servlet.jar files.  The AppEngine is not being used; I've seen the docs that mention that the AppEngine jar file contains implementations of the javax.mail classes, and that both the AppEngine jar and mail.jar should not be present in the classpath.
 
Using this configuration, when the log4j implementation tries to log an error message, the following debug info and stack trace is produced:

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]

java.lang.NoSuchMethodException: : com.sun.mail.smtp.SMTPTransport.<init>(javax.mail.Session, javax.mail.URLName)

along with an error message indicating that the SMTP provider can't be found:

javax.mail.NoSuchProviderException: smtp

However, I found that if I compile and deploy a much more complicated application with basically the same configuration to a Tomcat server, it works as expected.  This makes me suspect that the embedded server somehow contains mail.jar in its runtime classpath (I can't reference the classes in javax.mail in my project unless I include mail.jar in the classpath, so I'm positive they don't exist anywhere else in my project).  But, if I remove mail.jar from the WEB-INF lib directory and try to do a Class.forName on, say, javax.mail.Address, it can't be found.

Anyone have any ideas why this works when I deploy it, but not when running within Eclipse?

Thanks,
Ryan

Fatheranderson Ffather

unread,
Oct 9, 2013, 5:00:29 AM10/9/13
to google-we...@googlegroups.com

Hello i faced with problem:

javax.mail.NoSuchProviderException: smtp

         at javax.mail.Session.getService(Session.java:798)

                              

under running application in hosted mode. Can you give advise to me on fix this issue?

but I cant understand how to add special jar to bootstrap with gwt-maven-plugin.

I am trying this:

  <plugin>

                <groupId>org.codehaus.mojo</groupId>

                <artifactId>gwt-maven-plugin</artifactId>

                <version>2.4.0</version>

                <executions>

                    <execution>

                        <goals>

                            <goal>compile</goal>

                        </goals>

                    </execution>

                </executions>

                <configuration>

                    <module>com.db.dbtracer.paymentstp.webapp.PaymentsManagementApplication</module>

                    <runTarget>PaymentsManagementApplication.html</runTarget>

                    <draftCompile>true</draftCompile>

                    <optimizationLevel>1</optimizationLevel>

                    <extraParam>true</extraParam>

                    <extra>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</extra>

                    <extraJvmArgs>-cp ${project.build.directory}/${project.build.finalName}/WEB-INF/lib/mail-1.4.4.jar -Dapp.config=${project.build.outputDirectory}/etc/localhost.properties -Dnc.log4j.configuration=file:/${project.build.outputDirectory}/etc/log4j.xml -Dlog4j.debug</extraJvmArgs>

                </configuration>

            </plugin>

 

But it’s not make sense to me.

Ari Luoma

unread,
Oct 9, 2013, 6:15:30 AM10/9/13
to google-we...@googlegroups.com
Sorry, but I haven't used Maven and can't help you with that.
Reply all
Reply to author
Forward
0 new messages