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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Bocar Alpha Ba

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
: '[hidden email]',
 
from: '[hidden email]',
 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

--
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 [hidden email].
To post to this group, send email to [hidden email].
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 | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Justin Miranda
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

On Tue, Sep 20, 2016 at 8:45 AM, Bocar Alpha Ba <[hidden email]> wrote:

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
: '[hidden email]',
 
from: '[hidden email]',
 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

--
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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CADxhddT8pG0JUKpG3Jpf2xoz3xGEChitTZa8gDw3HQFFxRfCkA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Loading...