Grails 2.1 disables log4j config on JBoss - grails

We recently upgraded our app from Grails 1.3.7 to 2.1, which builds under maven, and made a bunch of changes to the pom file and other config- and build-related files of grails to get things working.
Here's the issue: when our JBoss server deploys our grails war file, something appears to cause log4j to be reconfigured such that the appserver stops all logging from that point forward (for any class). The app server is still running fine, but there is no logging after this line:
INFO [org.jboss.web.tomcat.service.deployers.TomcatDeployment] (main) deploy, ctxPath=/our-app
Removing our war file and restarting the server shows things logging correctly.
Our appserver has a server/default/conf/jboss-log4j.xml file in where we specify our cross-app log4j config.
I've tried removing log4j and slf4j jar files from our war, as that has caused issues in the past, but it hasn't solved the problem this time.
I also commented out the entire log4j section of grails-app/Config.groovy thinking that might be the culprit, but that had no effect.
I also tried removing the grails log4j plugin (by marking it as 'provided' scope in the pom), but that causes the following error during deployment:
ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/out-app]] (main) Error configuring application listener of class org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener
java.lang.ClassNotFoundException: org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener
Any idea what I might have missed?
An abbreviated listing of my war file is below:
WEB-INF/applicationContext.xml
WEB-INF/classes/BootStrap.class
WEB-INF/classes/BuildConfig.class
WEB-INF/classes/Config.class
WEB-INF/classes/DataSource.class
WEB-INF/classes/HibernateGrailsPlugin.class
WEB-INF/classes/UrlMappings.class
WEB-INF/classes/application.properties
WEB-INF/classes/gsp/views.properties
WEB-INF/classes/resources.class
WEB-INF/grails.xml
WEB-INF/jboss-web.xml
WEB-INF/lib/antlr-2.7.7.jar
WEB-INF/lib/aopalliance-1.0.jar
WEB-INF/lib/aspectjrt-1.6.10.jar
WEB-INF/lib/aspectjweaver-1.6.10.jar
WEB-INF/lib/cglib-2.2.jar
WEB-INF/lib/commons-beanutils-1.8.3.jar
WEB-INF/lib/commons-codec-1.5.jar
WEB-INF/lib/commons-collections-3.2.1.jar
WEB-INF/lib/commons-dbcp-1.4.jar
WEB-INF/lib/commons-el-1.0.jar
WEB-INF/lib/commons-fileupload-1.2.2.jar
WEB-INF/lib/commons-io-2.0.1.jar
WEB-INF/lib/commons-lang-2.6.jar
WEB-INF/lib/commons-pool-1.5.6.jar
WEB-INF/lib/commons-validator-1.3.1.jar
WEB-INF/lib/concurrentlinkedhashmap-lru-1.2_jdk5.jar
WEB-INF/lib/dom4j-1.6.1.jar
WEB-INF/lib/ehcache-core-2.4.6.jar
WEB-INF/lib/encryption-1.0.jar
WEB-INF/lib/ezmorph-1.0.6.jar
WEB-INF/lib/grails-bootstrap-2.1.0.jar
WEB-INF/lib/grails-core-2.1.0.jar
WEB-INF/lib/grails-crud-2.1.0.jar
WEB-INF/lib/grails-datastore-core-1.0.9.RELEASE.jar
WEB-INF/lib/grails-datastore-gorm-1.0.9.RELEASE.jar
WEB-INF/lib/grails-datastore-simple-1.0.9.RELEASE.jar
WEB-INF/lib/grails-hibernate-2.1.0.jar
WEB-INF/lib/grails-logging-2.1.0.jar
WEB-INF/lib/grails-plugin-codecs-2.1.0.jar
WEB-INF/lib/grails-plugin-controllers-2.1.0.jar
WEB-INF/lib/grails-plugin-converters-2.1.0.jar
WEB-INF/lib/grails-plugin-datasource-2.1.0.jar
WEB-INF/lib/grails-plugin-domain-class-2.1.0.jar
WEB-INF/lib/grails-plugin-filters-2.1.0.jar
WEB-INF/lib/grails-plugin-gsp-2.1.0.jar
WEB-INF/lib/grails-plugin-i18n-2.1.0.jar
WEB-INF/lib/grails-plugin-log4j-2.1.0.jar
WEB-INF/lib/grails-plugin-mimetypes-2.1.0.jar
WEB-INF/lib/grails-plugin-scaffolding-2.1.0.jar
WEB-INF/lib/grails-plugin-services-2.1.0.jar
WEB-INF/lib/grails-plugin-servlets-2.1.0.jar
WEB-INF/lib/grails-plugin-url-mappings-2.1.0.jar
WEB-INF/lib/grails-plugin-validation-2.1.0.jar
WEB-INF/lib/grails-resources-2.1.0.jar
WEB-INF/lib/grails-spring-2.1.0.jar
WEB-INF/lib/grails-web-2.1.0.jar
WEB-INF/lib/grails-webflow-2.1.0.jar
WEB-INF/lib/groovy-all-1.8.6.jar
WEB-INF/lib/hibernate-ehcache-3.6.10.Final.jar
WEB-INF/lib/hibernate-jpa-2.0-api-1.0.1.Final.jar
WEB-INF/lib/hibernate-validator-4.1.0.Final.jar
WEB-INF/lib/http-builder-0.5.0-RC3.jar
WEB-INF/lib/httpclient-4.0.jar
WEB-INF/lib/httpcore-4.0.1.jar
WEB-INF/lib/json-lib-2.3-jdk15.jar
WEB-INF/lib/jstl-1.1.2.jar
WEB-INF/lib/nekohtml-1.9.9.jar
WEB-INF/lib/oro-2.0.8.jar
WEB-INF/lib/sitemesh-2.4.jar
WEB-INF/lib/spring-aop-3.1.0.RELEASE.jar
WEB-INF/lib/spring-asm-3.1.0.RELEASE.jar
WEB-INF/lib/spring-aspects-3.1.0.RELEASE.jar
WEB-INF/lib/spring-beans-3.1.0.RELEASE.jar
WEB-INF/lib/spring-context-3.1.0.RELEASE.jar
WEB-INF/lib/spring-context-support-3.1.0.RELEASE.jar
WEB-INF/lib/spring-core-3.1.0.RELEASE.jar
WEB-INF/lib/spring-expression-3.1.0.RELEASE.jar
WEB-INF/lib/spring-jdbc-3.1.0.RELEASE.jar
WEB-INF/lib/spring-jms-3.1.0.RELEASE.jar
WEB-INF/lib/spring-orm-3.1.0.RELEASE.jar
WEB-INF/lib/spring-tx-3.1.0.RELEASE.jar
WEB-INF/lib/spring-web-3.1.0.RELEASE.jar
WEB-INF/lib/spring-webmvc-3.1.0.RELEASE.jar
WEB-INF/lib/util-io-1.2-SNAPSHOT.jar
WEB-INF/lib/utils-1.07.00.jar
WEB-INF/lib/validation-api-1.0.0.GA.jar
WEB-INF/lib/xml-resolver-1.2.jar
WEB-INF/lib/xpp3_min-1.1.4c.jar
WEB-INF/lib/zdecimal-3.2.jar
WEB-INF/plugins/hibernate-2.1.0/grails-app/i18n/messages.properties
WEB-INF/plugins/hibernate-2.1.0/plugin.xml
WEB-INF/sitemesh.xml
WEB-INF/web.xml
And Config.groovy (with app-specific stuff removed):
grails.project.groupId = appName // change this to alter the default package name and Maven publishing destination
grails.mime.file.extensions = true // enables the parsing of file extensions from URLs into the request format
grails.mime.use.accept.header = false
grails.mime.types = [
all: '*/*',
atom: 'application/atom+xml',
css: 'text/css',
csv: 'text/csv',
form: 'application/x-www-form-urlencoded',
html: ['text/html','application/xhtml+xml'],
js: 'text/javascript',
json: ['application/json', 'text/json'],
multipartForm: 'multipart/form-data',
rss: 'application/rss+xml',
text: 'text/plain',
xml: ['text/xml', 'application/xml']
]
grails.resources.adhoc.patterns = ['/images/*', '/css/*', '/js/*', '/plugins/*']
grails.views.default.codec = "none" // none, html, base64
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding = "UTF-8"
grails.views.gsp.sitemesh.preprocess = true
grails.scaffolding.templates.domainSuffix = 'Instance'
grails.json.legacy.builder = false
grails.enable.native2ascii = true
grails.logging.jul.usebridge = true
grails.spring.bean.packages = []
grails.hibernate.cache.queries = false
environments {
production {
grails.logging.jul.usebridge = false
}
development {
grails.logging.jul.usebridge = true
}
test {
// shouldn't be using this environment
}
}

Through some debugging breakpoints, I was able to determine that the Grails log4j plugin is the culprit. It appears to be resetting the global log4j config on startup.
I'll ask a separate question about how to disable this.
see How do disable log4j plugin in grails?

Related

Grails: excluding a JS file from minification

I read tons of documentation on asset-pipeline Grails plugin, but found no definite answers and I can not exclude a single stupid JS file from being minified.
Grails is in ver. 3.3.6 and assetPipelineVersion 2.14.1.
Goal:
Stop minifying grails-app/assets/javascripts/json-tree/json-tree.js.
What I tried:
I changed the assets block in build.gradle:
assets {
minifyJs = true
minifyCss = true
includes = []
excludes = [ '**/json-tree.js' ] // tried also with 'json-tree/json-tree.js'
}
I also added a section to my application.yml:
grails:
assets:
excludes: ['json-tree/*.js'] # also tried with **
Problem: the file still gets minified.
How can I solve the problem?
Also, how the assets pipeline should be configured: per build.gradle or application.yml or both?
Please try with following :
grails.assets.minifyOptions.excludes = ["json-tree/json-tree.js"]
To exclude single file you can try above otherwise you can exclude whole folder from minify
grails.assets.minifyOptions.excludes = ["json-tree/*.js"]
For more information you check documentation
Hope this will help you

getting grails 2.5.4 asset pipeline excludes to work

I am unable to get either the sass asset pipeline or the less asset pipeline plugin to work, if I am using sass or less imports.
If I only have one sass or less file, grail war works fine.
In my scenario however, file1.scss imports file2.scss, and in the end I only want to end up with a file1.css created from both. This should be possible according to this
https://grails.org/plugin/sass-asset-pipeline
But I am getting this output
| Minifying File 345 of 398 - file2.
| Error WAR packaging error: Stream closed
from grails war --stacktrace --verbose
Both files are in the same directory and have teh following contents:
file1.scss
#import "file2";
.brand {background-color:$mainColor;}
file2.scss
$mainColor: #277D85;
My build config has this:
plugins = {
...
compile ':asset-pipeline:2.5.7'
provided ":sass-asset-pipeline:2.9.1"
}
grails.assets.minifyJs = false
grails.assets.minifyCss = false
grails.assets.minifyOptions = [
optimizationLevel: 'WHITESPACE_ONLY'
]
grails.assets.excludes = ["**/file2.scss"]
What am I doing wrong?
How can I get more insights into what's going on here.
Your plugin block should remain in BuildConfig.groovy. However, the rest should be placed in Config.groovy

Grails log4j SMTPAppender NoClassDefFoundError

How do I configure SMTPAppender in a new Grails 2.4.5 project? I receive a NoClassDefFoundError when running in the development environment:
| Error log4j:ERROR Error initializing log4j: javax/mail/Message
| Error java.lang.NoClassDefFoundError: javax/mail/Message
Gist: Detailed stacktrace
I have configured a dependency for javax.mail and configured log4j as follows:
dependencies {
provided 'javax.mail:mail:1.4.7'
}
log4j = {
appenders {
appender new org.apache.log4j.net.SMTPAppender(
name: 'smtp',
layout: pattern(conversionPattern: '%d{MM-dd-yyyy HH:mm:ss.SSS} [%t] %c %M %x%n%p: %m%n')
to: 'example#example.com',
from: 'example#example.com',
subject: 'Grails Message',
SMTPHost: '127.0.0.1')
)
}
}
GitHub: Example Project
I know this post is old, but I struggled with the same till I found a solution that is at least working for me (not with SMTPAppender but with Sentry - same purpose).
The explanation I found with the errors you where receiving
Error log4j:ERROR Error initializing log4j: javax/mail/Message
Error java.lang.NoClassDefFoundError: javax/mail/Message
Come from this piece of code:
dependencies {
provided 'javax.mail:mail:1.4.7'
}
The thing is that when you compile things work, when you try to do grails run-app you receive this error.
The explanation I found is that the log4j initializes before the maven dependency is resolved.
I wrote a comment of how I've used Sentry as an appender.
https://github.com/getsentry/raven-java/issues/184#issuecomment-259432057
Basically, instead of adding the maven dependency I've downloaded the java file, and added it to the grails project in src/java
So for Sentry por example I added the SentryAppender.java to my.package.sentry so then in log4j I added:
appenders {
environments {
// This block is set up to use the stock raven SentryAppender in
// production. Sentry Appender runs into all kinds of
// class loading weirdness when used in a forked grails environment
production {
appender new my.package.sentry.SentryAppender(
name: 'sentry',
dsn: 'REDACTED',
threshold: org.apache.log4j.Level.WARN
)
}
// Uncomment this block if you need to test sentry
// in a dev environment
development {
appender new my.package.sentry.SentryAppender(
name: 'sentry',
dsn: 'REDACTED',
threshold: org.apache.log4j.Level.WARN
)
}
}
}
root {
warn 'stdout', 'sentry'
error 'stdout', 'sentry'
additivity = false
}
in that way, it does not depend on an external dependency.
I guess that you could do something similar to the mail dependency and add the java files to the src folder.
I hope it helps!
That looks weird - are you combining the dependencies block and the log4j block here unintenionally, or are they in the same file in your app? The dependency should be in BuildConfig.groovy and the log4j block should be in Config.groovy. Also, it shouldn't be log4j { but rather log4j = {.
This is likely a timing issue. If Config.groovy is parsed before the Javamail dependency is resolved, it will fail. Try commenting out the parts that reference the Javamail classes and run grails clean and grails compile. That will resolve dependencies and add that jar to the classpath. Then you can uncomment that code and run grails compile again.

Connect to FileMaker Database from Grails app

I can't achieve to connect with a FileMaker database when I use the fmjdbc driver. I put the jar library in the /lib folder and I try connect with the next connection params:
dataSource {
pooled = true
driverClassName = "com.ddtek.jdbc.sequelink.SequeLinkDriver"
username = "myUser"
password = "myPass"
}
...
test {
dataSource {
dbCreate = "update"
url ="jdbc:sequelink://myIP:2399;serverDataSource=mydataBase;user=myUser;password=myPass"
}
}
Unfortunately, It return a ClassNotFoundException error:
"...
Caused by SQLNestedException: Cannot load JDBC driver class 'com.ddtek.jdbc.sequelink.SequeLinkDriver'
...
"
I think It could be a unregister-dependency lack, as well as the runtime dependency of mysql driver placed at buildConfig.groovy file:
dependencies {
runtime 'mysql:mysql-connector-java:5.1.16'
}
I have seen the manifest.mf jar file but This don't have any relevant data. Here the content:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.0
Created-By: 1.5.0_26-156 (Apple Inc.)
but I don't know how build the dependency string for com.ddtek.jdbc.sequelink.SequeLinkDriver driver..
Anybody says how could be it? Will It be the problem, or maybe coud be another?
Thanks a lot.
Luis.

How do disable log4j plugin in grails?

It appears the Grails 2.1 log4j plugin resets the log4j configuration during initialization of the grails application (see stack trace below).
at org.apache.log4j.LogManager.resetConfiguration(LogManager.java:233)
at org.apache.log4j.LogManager$resetConfiguration.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at org.codehaus.groovy.grails.plugins.log4j.Log4jConfig.initialize(Log4jConfig.groovy:66)
at org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener.contextInitialized(Log4jConfigListener.java:48)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3910)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4389)
at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeployInternal(TomcatDeployment.java:313)
at org.jboss.web.tomcat.service.deployers.TomcatDeployment.performDeploy(TomcatDeployment.java:145)
Is there any way to disable this "feature" or to remove this plugin altogether?
My JBoss server is already configured through jboss-log4j.xml and I do not want grails to make any changes to the configuration. I have already tried removing the log4j section of Config.groovy, but doing so had no effect.
As Kelly suggested, I have already removed all logging-related jars from my war file. Log4j classes are provided by JBoss.
EDIT I also tried the trick described in https://stackoverflow.com/a/1190438/539048 but that didn't seem to make any difference.
The solution was to remove the following section from the generated web.xml file:
<listener>
<listener-class>org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener</tag0:listener-class>
</listener>
To do so, I edited the scripts/Events.groovy file according to this blog but changed the listener class name to org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener.
eventWebXmlEnd = {String tmpfile ->
def root = new XmlSlurper().parse(webXmlFile)
def log4j = root.listener.findAll {node ->
node.'listener-class'.text() == 'org.codehaus.groovy.grails.plugins.log4j.web.util.Log4jConfigListener'
}
log4j.replaceNode {}
webXmlFile.text = new StreamingMarkupBuilder().bind {
mkp.declareNamespace("": "http://java.sun.com/xml/ns/j2ee")
mkp.yield(root)
}
}
Modify your BuildConfig.groovy like this:
inherits("global") {
excludes 'log4j', 'jcl-over-slf4j', 'slf4j-api', 'slf4j-log4j12'
}
This should remove all the logging libraries.
I tried the above suggestion on this grails application, so that I could expect to exclude the log4j dependencies of grails. However, after applying the suggestion, the jar files expected to be removed are still there in the generated war file. These jar files are: ./lib/grails-plugin-log4j-2.4.4.jar and ./lib/log4j-1.2.17.jar

Resources