Ant + Log4j

Hibernate’s SchemaExportTask ant task always gives very informative error messages (not! Smiling). Here’s an example:

BUILD FAILED
build.xml:267: Schema text failed: Could not parse mapping document from file SomeClass.hbm.xml

To get some useful info on what went wrong we need to specify a log4j configuration file:

niklas@niklas:~$ ANT_OPTS=-Dlog4j.configuration=file:///path/to/log4j.properties ant some-task

Don’t forget file://!

Here’s a simple log4j.properties file you could use:

log4j.rootLogger=DEBUG, consoleAppender
log4j.appender.consoleAppender=org.apache.log4j.ConsoleAppender
log4j.appender.consoleAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.consoleAppender.layout.ConversionPattern=%d [%t] %-5p %c %x - %m%n