Question

I just tried to read a grails config from groovy. The ConfigSlurper is easy to use, but since it executes the config, it needs all dependencies in place. In my case, it complains about a missing log4j class. Even when I import this class into my ConfigSlurper script, the config itself runs into this problem.

Any Idea how I could make the log4j classes accessible to the config?

Update: now that I have a proper keyboard in front of me, I can elaborate on my problem:

I have grails configurations which configure log4j as described in the docs:

import org.apache.log4j.*

log4j = { 
  appenders { 
    appender new RollingFileAppender( 
         name: "myAppender", 
         maxFileSize: 1024, 
         file: "/tmp/logs/myApp.log"
    ) 
  } 
}

Then I tried to parse them like this:

def file = new File(<config location>)
def config = new ConfigSlurper().parse(file.toURL())

and the Slurper threw an exception...

Was it helpful?

Solution

I've found two solutions:

First, the documents show a way how to configure a rollingFileAppender without instantiating one: http://grails.org/doc/2.3.7/guide/conf.html .

Second, I managed to fix my original problem with a

@Grab('log4j:log4j:')

in front of my script - not a good solution if you are behind a firewall...

As Jeff already stated, it should also be possible to put the right jar file in the classpath, but I have to say that I often struggle with the cp :-( and when I tried to put the log4j.jar in the .groovy folder, I didn't succeed - but I guess this was because of an inproper groovy installation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top