geeky · non php code

log4j properties loading problem + put ivy jar on classpath in ant

I learned a few new tricks recently that I thought are pretty cool.

If you use apache log4j, you can get very frustrated sometimes that it does not log based on what you defined in your file. This is because if your java web application contains other jars that also have, the log4j will use the first on the classpath which most of the times is NOT what you defined for your web app. I never knew a solution to this until recently my coworker was able to use spring to get around it. In your spring context, add

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
  <property name="targetClass" value="org.springframework.util.Log4jConfigurer"/>
  <property name="targetMethod" value="initLogging" />
  <property name="arguments">

This will make sure the one you defined for your web app is used.

Also I recently wrote a groovy script in ant. I learned that you can use ivy to cache as instance of a jar and then you can use it in your ant script.

<target name="groovyScript">
  <ivy:configure url="" />
  <ivy:resolve conf="ant"/>
  <ivy:cachepath pathid="cp" conf="ant"/>
  <taskdef name="groovy" classpathref="cp" classname="org.codehaus.groovy.ant.Groovy"/>
	<!-- your groovy script here -->

On the other note, I heard if you were going to hack to use groov

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s