log4j:ERROR Error initializing log4j: Ljavax/mail/Message;

41 views
Skip to first unread message

Bocar Alpha Ba

unread,
Sep 20, 2016, 9:45:25 AM9/20/16
to Grails Dev Discuss

Hi, 

I want to send an email when I have an exception with log4j . But this is what I have after my application launch



Error | log4j:ERROR Error initializing log4j: Ljavax/mail/Message; Error | java.lang.NoClassDefFoundError: Ljavax/mail/Message; Error | at java.lang.Class.getDeclaredFields0(Native Method) Error | at java.lang.Class.privateGetDeclaredFields(Class.java:2575) Error | at java.lang.Class.getDeclaredFields(Class.java:1908) Error | at org.springsource.loaded.ri.ReflectiveInterceptor.jlClassGetDeclaredFields(ReflectiveInterceptor.java:1796) Error | at org.codehaus.groovy.reflection.CachedClass$1$1.run(CachedClass.java:53) Error | at java.security.AccessController.doPrivileged(Native Method) Error | at org.codehaus.groovy.reflection.CachedClass$1.initValue(CachedClass.java:50)

Below my config.groovy
log4j.main = {
 
// Example of changing the log pattern for the default console appender:
 appenders
{
 
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
 console name
:'stdout', layout:pattern(conversionPattern: '%d %-5p %c{1} - %m%n')
 appender
new SMTPAppender(name: 'smtp',
 threshold
: org.apache.log4j.Level.ERROR,
 to
: 'ma...@echarp.org',
 
from: 'boca...@docapost.fr',
 subject
: '[Application Error]',
 
SMTPHost: '127.0.0.1')
 
}
 root
{
 info
'stdout', 'file'
 error
'stdout', 'smtp'
 additivity
= false


 
}


And below my buildconfig.groovy (snippet related to the purpose)


dependencies
{

provided
'javax.mail:mail:1.4.7'
 provided
'javax.mail:javax.mail-api:1.5.1'
 provided
'javax.activation:activation:1.1' }


Last thing: I tried to clean and compile the project after commented the provided dependencies then comment and run the projet but it changed nothing

Any ideas please

Justin Miranda

unread,
Sep 20, 2016, 10:36:55 AM9/20/16
to grails-de...@googlegroups.com
Are you sure you want to use "provided"? That means that the JDK or container (Tomcat, Jetty, whatever) will provide the dependency for you. I'm not sure if that is the case. Perhaps it does, but you may want to try "compile" scope instead.  

dependencies { 
 compile 
'javax.mail:mail:1.4.7'
 compile 
'javax.mail:javax.mail-api:1.5.1'
 compile 
'javax.activation:activation:1.1' }

And if that still doesn't work, try to refresh the dependencies explicitly

$ grails compile --refresh-dependencies

One thing to note about changing the scope of the dependency is that you may now have multiple javax.mail:mail dependencies being pulled in. I believe Maven/Ivy should handle the conflicts automatically, but sometimes it gets confused. If you start seeing issues related to method signatures (which imply that you have multiple versions of the same dependency), you may need to run a dependency report and add excludes to BuildConfig for any dependencies that you don't want to be included.

Finally, I assume you are trying to add an SMTP Appender so that you can collect all exceptions that are thrown by your application. I used SMTPAppenders for this purpose for a long time and would occasionally check to see if I needed to deal with any of the errors. The exception email inbox associated with one of my applications eventually became overwhelming and I stopped checking it a long time ago (it's sitting at 5000 messages right now). 

I would recommend using Sentry (+ Grails Raven plugin) instead of an SMTPAppender. I've migrated to Sentry for most of my applications and it's really really nice.

Grails Sentry plugin: https://grails.org/plugin/raven

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grails-dev-discuss+unsub...@googlegroups.com.
To post to this group, send email to grails-dev-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/f074742b-f10f-4f1d-a6b8-14d762d1e8ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages